akhauriyash/Code-Regression huggingface dataset:
hori_verti = input().split()
horisontal = int(hori_verti[0])
vertical = int(hori_verti[1])
input_grid = [input() for element in range(horisontal)]

remove_yoko_list = set()
remove_tate_list = set()

def scan(grid_verti_list):
  for ele in grid_verti_list:
    if ele != '.':
      return False
  return True

def scan_column():
  for tate in range(vertical):
    row = []
    for yoko in range(horisontal):
      row.append(input_grid[yoko][tate])
    if scan(row):
      remove_tate_list.add(tate)      

for hori_num in range(horisontal):
  grid_verti_list = input_grid[hori_num]
  if scan(list(grid_verti_list)):
    remove_yoko_list.add(hori_num)
    
scan_column()

res = []
for x in range(horisontal):
  keep = []
  if x in remove_yoko_list:
    continue
  for (y, letter) in enumerate(input_grid[x]):
    if y in remove_tate_list:
      continue
    keep.append(letter)
  res.append(keep)
      
result = []  
for str in res:
  new_line_list = ''.join(str)
  result.append(new_line_list)

if(len(result) == 0):
  print('\n'.join(input_grid))
else:
  print('\n'.join(result))

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int r, c, sumOfAll = 0;
  cin >> r >> c;
  vector<vector<int>> sheet;
  sheet.resize(r, vector<int>(c));
  vector<int> totalRows(r, 0), totalColumns(c, 0);

  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      int x;
      cin >> x;
      sheet[i][j] = x;
      sumOfAll += x;
      totalRows[i] += x;
      totalColumns[j] += x;

      cout << x << ' ';
    }
    cout << totalRows[i] << endl;
  }

  for (int i = 0; i < c; i++) {
    cout << totalColumns[i] << ' ';
  }
  cout << sumOfAll << endl;

  return 0;
}



Measured memory_bytes: 3156
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define MOD 1000000007
const ll inf = 1e9 + 1;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,wt;
    cin>>n>>wt;
    int mxn = n*1000;
    ll w[n+1],v[n+1];
    ll dp[n+1][mxn+1];

    for(int i= 1; i<=n; i++){
        cin>>w[i]>>v[i];
    }
    
    for(int j = 0; j<=mxn; j++){
            dp[1][j] = inf;
    }
        dp[1][0] = 0;
        dp[1][v[1]] = w[1];
    for(int i = 2; i<=n; i++){
        for(int j = 1; j<=mxn; j++){
            dp[i][j] = dp[i-1][j];
            if(j>=v[i]){
                dp[i][j] = min(dp[i][j], dp[i-1][j - v[i]] + w[i]);
            }
        }
    }
    int ans = 0;
    for(int i = mxn; i>=1; i--){
        if(dp[n][i] <=wt){
            ans = i;
            break;
        }
    }
    cout<<ans;

}


Measured memory_bytes: 79104
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <numeric>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

#define rep(i,n) for(int i = 0; i<n ; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)
#define REPSTR(i,s) for(int i=0; (s)[i]; i++)
#define REPITR(i,s) for(auto i=(s)begin(); i!=(s).end();i++)

#define RANGE(a,i,b) ((a)<=(i)&&(i)<=(b))

#define pb push_back
#define mp make_pair

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

#define EXIST(s,x) ((s).find(x)!=(s).end())

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

#ifdef _DEBUG
#define DEBUG(x) cerr<<#x<<":"<<x<<endl
#else
#define DEBUG(x)
#endif

#define PRINTJOIN(x,n) rep(i,n){if(i)cout<<" ";cout<<x[i];}cout<<endl 

#define INF 1001001001
#define LLINF 1001001001001001001LL

typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef stringstream SS;

#define PQ priority_queue

#define FST first
#define SEC second

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

//------------------HEAD---------------------

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x, y;
	cin >> x >> y;
	if (x >= y/2) {
		cout << y / 2 << endl;
	}else{
		y = y - x * 2;
		cout << x + y / 4 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e10
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	//sc.Split(bufio.ScanWords)

	s := next()
	fmt.Println(s[:3])

}

func intSlicePrint(el ...int) {
	first := true
	for _, v := range el {
		if v < 0 {
			continue
		}
		if !first {
			fmt.Printf(" ")
		}
		fmt.Printf("%v", v)
		first = false
	}
	fmt.Println("")
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


Measured memory_bytes: 1756
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	ll n;
	cin>>n;
	ll arr[n],dp[n];
	dp[0]=0;
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	dp[1]=abs(arr[0]-arr[1]);
	for(ll i=2;i<n;i++)
	{
		dp[i]=min((dp[i-1]+abs(arr[i-1]-arr[i])),(dp[i-2]+abs(arr[i-2]-arr[i])));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  int n, at = 0, ax = 0, ay = 0, t, x, y;
  cin >> n;
  rep(i,n)
  {
    cin >> t >> x >> y;
    if (abs(t - at) >= (abs(x - ax) + abs(y - ay)) && (x + y + t) % 2 == 0) {
      at = t, ax = x, ay = y;
    } else {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << #x << "]: " << (x) << endl;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    vector<double> dp(n+1);
    dp[0] = 1;

    for (int i=0; i<n; i++) {
        double x;
        cin >> x;
        for (int j=n; j>0; j--) {
            dp[j] = dp[j-1]*x + dp[j]*(1-x);
        }
        dp[0] = dp[0]*(1-x);
    }
    double ans = 0;
    for (int i=n/2+1; i<n+1; i++)
        ans += dp[i];

    cout << setprecision(10) << fixed << ans << "\n";
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  string s;
  cin >> s;

  if (s == "Sunny") {
    cout << "Cloudy" << endl;
  } else if (s == "Cloudy") {
    cout << "Rainy" << endl;
  } else {
    cout << "Sunny" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

    static void solve() {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();

        int[] prices = new int[n];
        for (int i = 0; i < n; i++) {
            prices[i] = scan.nextInt();
        }
//        long stocks = 0;
        long cash = 1000;
        for(int i=0;i<prices.length-1;i++) {
            if(prices[i] < prices[i+1]) {
                //buy
                long stocks = (cash/prices[i]);
                cash -= stocks * prices[i];
                cash += stocks*prices[i+1];
            }
        }
        System.out.println(cash);
       // return ans;


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

//        int t = scan.nextInt();
//        for (int i = 0; i < t; i++) {
//            int n = scan.nextInt();
//            int[] arr1 = new int[n];
//            for (int j = 0; j < n; j++) {
//                arr1[j] = scan.nextInt();
//            }
////            scase(n, arr1);
//        }


//        long t = scan.nextLong();

//        for (int i = 0; i < t; i++) {
//            int n = scan.nextInt();
////            scase(n);
//        }
    }


    static void solveCase(int t, int x, String s) {

    }

    static void scase(int[] arr1, int[] arr2) {
    }


    public static void main(String[] args) {

        solve();

    }


//
//    class Counter extends HashMap<Integer, Integer> {
//        public int get(int k) {
//            return containsKey(k) ? super.get(k) : 0;
//        }
//
//        public void add(int k, int v) {
//            put(k, get(k) + v);
//        }
//    }

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}

Measured memory_bytes: 27232
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define mod 1000000007
using namespace std;
int main(){
    int W,H,x,y,r;   cin>>W>>H>>x>>y>>r;
    if(x>W-r||x<r){
        cout<<"No"<<endl;
        return 0;
    }
    if(y>H-r||y<r){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 3108
<?php

$nm = explode(" ", trim(fgets(STDIN)));
$a = explode(" ", trim(fgets(STDIN)));

$q = new SplPriorityQueue();
for ($i = 0; $i < count($a); $i++) {
     $q->insert($i, $a[$i]);
}

$count = $q->count();
for ($i = 0; $i < $nm[1]; $i++) {
    $tmp = $q->extract();
    $a[$tmp] = floor($a[$tmp] / 2);
    
    $q->insert($tmp, $a[$tmp]);
}

echo array_sum($a);

Measured memory_bytes: 57844
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

bool IsGood(int x, const vector<int>& d) {
  for (int y : d) {
    while (x % y == 0) x /= y;
  }
  return x == 1;
}

int main()
{
  int n;
  cin >> n;
  if (n == 2) {
    printf("4 7\n23 10\n");
    return 0;
  }
  const int BUBEN = 3e6;
  vector<bool> p(BUBEN, true);
  vector<ll> primes;
  for (int i = 2; i < BUBEN; ++i) {
    if (!p[i]) continue;
    primes.push_back(i);
    if (primes.size() >= 10000) break;
    for (int j = i; j < BUBEN; j += i) p[j] = false;
  }
  vector<int> odd, even;
  for (int i = 0; i < 2 * n; ++i) {
    if (i % 2) odd.push_back(primes[i]); else even.push_back(primes[i]);
  }
  vector<ll> x, y;
  for (int cur = 2; ; ++cur) {
    if (x.size() == n && y.size() == n) break;
    if (x.size() < n && IsGood(cur, odd)) {
      x.push_back(cur);
    } else if (y.size() < n && IsGood(cur, even)) {
      y.push_back(cur);
    }
  }

  vector<vector<vector<ll>>> mul(n, vector<vector<ll>>(n));
  vector<vector<ll>> ans(n, vector<ll>(n, 1));

  for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
    if ((i + j) % 2 == 1) continue;
    mul[i][j].push_back(x[(i + j) / 2]);
    ans[i][j] *= mul[i][j].back();
  }

  for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
    if ((i + j) % 2 == 1) continue;
    mul[i][j].push_back(y[(i - j + n - 1) / 2]);
    ans[i][j] *= mul[i][j].back();
  }

  for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
    if ((i + j) % 2 == 0) continue;
    set<ll> cur;
    for (int di = -1; di <= 1; ++di) for (int dj = -1; dj <= 1; ++dj) if (di * di + dj * dj == 1) {
      int ii = i + di;
      int jj = j + dj;
      if (ii < 0 || ii >= n || jj < 0 || jj >= n) continue;
      for (ll x : mul[ii][jj]) cur.insert(x);
    }
    for (ll x : cur) ans[i][j] *= x;
    ans[i][j]++;
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (j) cout << " ";
      cout << ans[i][j];
    }
    cout << endl;
  }


  map<ll, vector<pair<int, int>>> mp;
  for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) mp[ans[i][j]].push_back(make_pair(i, j));
  for (auto it : mp) {
    if (it.second.size() > 1) {
      cerr << "BOTVA\n";
      cerr << it.first << endl;
      cerr << it.second[0].first << " " << it.second[0].second << endl;
      cerr << it.second[1].first << " " << it.second[1].second << endl;
      //return 0;
    }
  }

  for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
    assert(ans[i][j] < 1e15);
    for (int di = -1; di <= 1; ++di) for (int dj = -1; dj <= 1; ++dj) if (di * di + dj * dj == 1) {
      int ii = i + di;
      int jj = j + dj;
      if (ii < 0 || ii >= n || jj < 0 || jj >= n) continue;
      ll a = ans[i][j];
      ll b = ans[ii][jj];

      assert(max(a, b) % min(a, b) == 1);
    }
  }

  
  return 0;
}


Measured memory_bytes: 42368
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
//const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    int N; cin>>N;
    vector<int> C(N),S(N),F(N);

    for (int i = 0; i < N-1; ++i) {
        cin>>C[i]>>S[i]>>F[i];
    }

    for (int i = 0; i < N; ++i) {
        int ans=0;
        for (int j = i; j < N-1; ++j) {
            if(ans<S[j]) ans=S[j]+C[j];
            else{
                ans=(ans-1+F[j])/F[j]*F[j]+C[j];
            }
        }
        cout<<ans<<endl;
    }

}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


Measured memory_bytes: 256
/*;

THE BEST IS YET TO COME
*/
#include <bits/stdc++.h>
using namespace std;
#define r(i, s, l) for (int i = s; i < l; i++)
#define rr(i,s,l) for(int i=s;i>=l;i--)
#define mod 1000000007
#define int long long
#define INT_BITS 32
#define ld long double
#define pp pair<int,int>
#define ss second
#define ff first
#define INF 1e18
#define N 2000005
#define all(a) a.begin(), a.end()
#define pb push_back
#define endl "\n"
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

signed main()
{


    vector<int> a(5);
    r(i,0,5)
    cin>>a[i];

    r(i,0,5)
    if(a[i]==0)
    {
        cout<<i+1;
        return 0;
    }
	return 0;
}



Measured memory_bytes: 3596
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main(void) {
	string s;
	string t;
	cin >> s >> t;
	ll count = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3848
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	string s; cin>>s;
	int ret=0;
	for (int i=0; i<=n; i++) {
		string a=s.substr(0,i), b=s.substr(i);
		set<char> st(a.begin(), a.end()), cur(b.begin(), b.end());
		int val=0;
		for (auto it : cur)
			if(st.find(it)!=st.end())
				val++;
		ret=max(ret,val);
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 01/03/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);

  map<int, pair<int, int>> places;
  bool card[3][3] = {};
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      int a;cin>>a;
      places[a] = {i, j};
    }
  }
  int n; cin>>n;
  for (int i = 0; i < n; i++) {
    int b; cin>>b;
    if (places.count(b) == 0)
      continue;
    card[places[b].first][places[b].second] = true;
  }

  bool ans = false;
  for (int i = 0; i < 3; i++) {
    ans |= card[i][0] & card[i][1] & card[i][2];
    ans |= card[0][i] & card[1][i] & card[2][i];
  }
  ans |= card[0][0] & card[1][1] & card[2][2];
  ans |= card[0][2] & card[1][1] & card[2][0];

  cout << (ans ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define INF 10000000000

using namespace std;
int main(void){
    int N;
    cin>>N;
    long A[N];
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A,A+N);
    if(N!=2){
      long min=INF; long ans=0;
      for(int i=0;i<N-1;i++){
          if(min>abs(A[N-1]-2*A[i])){min=abs(A[N-1]-2*A[i]); ans=A[i];}
      }
      cout<<A[N-1]<<' '<<ans;
    }
    else {cout<<A[1]<<' '<<A[0];}
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll modpow(ll x, ll n){
    ll res = 1;
    while(n > 0){
        if(n % 2){
            res = (res * x) % MOD;
        }
        x = (x * x) % MOD;
        n /= 2;
    }
    return res;
}
    

int main()
{
    string s;
    cin >> s;
    ll q = 0;
    ll sa = 0;
    ll sc = 0;
    ll n = s.size();
    for(int i = 0; i < n; i++){
        if(s[i] == '?'){
            q++;
        }
        if(s[i] == 'A'){
            sa++;
        }
        if(s[i] == 'C'){
            sc++;
        }
    }
    ll a[100001] {0};
    ll c[100001] {sc};
    ll lq[100001] {0};
    ll rq[100001] {q};
    if(s[0] == 'C'){
        c[0] = sc - 1;
    }
    if(s[0] == '?'){
        rq[0] = q - 1;
    }
    for(int i = 1; i < n; i++){
        a[i] = a[i - 1];
        if(s[i - 1] == 'A'){
            a[i]++;
        }
        lq[i] = lq[i - 1];
        if(s[i - 1] == '?'){
            lq[i]++;
        }
        c[i] = c[i - 1];
        if(s[i] == 'C'){
            c[i]--;
        }
        rq[i] = rq[i - 1];
        if(s[i] == '?'){
            rq[i]--;
        }
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll ansi = 0;
        if(s[i] == 'B'){
            ansi = ((a[i] * c[i]) % MOD) * modpow(3, q) + ((lq[i] * c[i]) % MOD) * modpow(3, q - 1) + ((a[i] * rq[i]) % MOD) * modpow(3, q - 1) + ((lq[i] * rq[i]) % MOD) * modpow(3, q - 2);
        }
        if(s[i] == '?'){
            ansi = ((a[i] * c[i]) % MOD) * modpow(3, q - 1) + ((lq[i] * c[i]) % MOD) * modpow(3, q - 2) + ((a[i] * rq[i]) % MOD) * modpow(3, q - 2) + ((lq[i] * rq[i]) % MOD) * modpow(3, q - 3);
        }
        ans = (ans + ansi) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3584
#include<stdio.h>
#define MAX 100
#define INF 100000000

int main()
{
  int n,p[MAX],i,j,k,l,m[MAX+1][MAX+1],q;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d%d",&p[i],&p[i+1]);
  }

  for(i = 1; i <= n; i++){
    m[i][i] = 0;
  }

  for(l = 2; l <= n; l++){
    for(i = 1; i <= n-l+1; i++){
      j = i + l -1;
      m[i][j] = INF;
      for(k = i; k <= j-1; k++){
	q = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
	if(q < m[i][j]) m[i][j] = q;
      }
    }
  }

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

  return 0;
}

Measured memory_bytes: 636
#include <cstdio>
#include <algorithm>

int n,a[200005];
long long Ans;

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",&a[i]),a[i]-=i;
    std::sort(a+1,a+n+1);
    for(int i=1;i<=n;++i)Ans+=abs(a[i]-a[n+1>>1]);
    printf("%lld\n",Ans);
    return 0;
}

Measured memory_bytes: 896
#!/usr/bin/env python3

#import
#import math
#import numpy as np
N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [10 ** 9] * N
dp[0] = 0

for i in range(N):
    for j in range(1, K + 1):
        if i + j >= N:
            break

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

print(dp[-1])



Measured memory_bytes: 84816
// In the name of Allah
// #Isart

#include<bits/stdc++.h>

#define pii pair<int, int>
#define pb push_back
#define F first
#define S second
#define ll long long
#define ld long double

using namespace std;

const int MAXN = 1e5 + 10;
vector<int> a[MAXN];
int d[MAXN], sz[MAXN], par[MAXN];

void dfs(int v, int parent){
	for(auto u : a[v]){
		if(u == parent) continue;
		d[u] = d[v] + 1;
		par[u] = v;
		dfs(u, v);
		sz[v] += sz[u];
	}
	sz[v] ++;
}

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	for(int i = 0; i < n - 1; i ++){
		int x, y; cin >> x >> y;
		a[x].pb(y), a[y].pb(x);
	}	
	dfs(1, 0);
	int v = n, last = -1;
	while(d[v] > d[n]/2){
		last = v;
		v = par[v];
	}
	if(sz[last] >= n - sz[last]) cout << "Snuke" << endl;
	else cout << "Fennec" << endl;
	return 0;	
}

Measured memory_bytes: 13184
#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  ll n, X; cin >> n >> X;
  vector<ll> x(n);
  for(ll i = 0; i < n; i++){
    cin >> x[i];
    x[i] = abs(x[i] - X);
  }
  ll ans = x[0];
  for(int i = 0; i < n-1; i++) {
    ans = min(ans, __gcd(x[i], x[i+1]));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(){
    int x,y,m,s,k;
    scanf("%d%d%d",&x,&y,&m);
s=x*y;
    if(s<=m){
        printf("%d\n",s);
    }
    else if(s>m) {
        printf("%d\n",m);
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int n,T;
  cin>>n>>T;
  vector<int> root;
  for(int i=0;i<n;i++){
    int c,t;
    cin>>c>>t;
    if(t<=T){
      root.push_back(c);
    }
  }
  if(root.size()==0){
    cout<<"TLE";
    return 0;
  }
  sort(root.begin(),root.end());
  cout<<root[0];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>         vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)            for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

int main() {
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

  int x;
  cin >> x;
  cout << !x << endl;
  return 0;
}



Measured memory_bytes: 3580
#include<bits/stdc++.h>

using namespace std;

#define rep(i, a, b)  for(int i = (a); i < (b); i++)
#define rrep(i, a, b) for(int i = (a); i > (b); i--)
#define sq(x) ((x) * (x))
#define bit(x) bitset<8>(x)
#define vsort(v)  sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<int>())
#define debug(x) cout << #x << " " << (x) << endl
#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1e9+7

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


template<typename Tn> Tn __lcm(Tn a, Tn b)
{
    return a / __gcd(a, b) * b;
}

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

int main()
{
    map<int, int> m;
    int a[100001];
    int n;
    ci >> n;

    vi v;

    rep(i, 0, n) {
	ci >> a[i];
	if(!m[a[i]]) {
	    v.pb(a[i]);
	    m[a[i]] = 1;
	} else {
	    m[a[i]]++;
	}
    }
    
    if(v.size() == 3 && m[v[0]] == m[v[1]] && m[v[1]] == m[v[2]]) {
	if((v[0] ^ v[1]) == v[2] || (v[1] ^ v[2]) == v[0] || (v[2] ^ v[0]) == v[1])
	    co << "Yes" << en;
	else
	    co << "No" << en;
    } else if(v.size() == 2 && (m[v[0]] == m[v[1]] * 2 || m[v[0]] * 2 == m[v[1]]) && min(v[0], v[1]) == 0) {
	co << "Yes" << en;
    } else if(v.size() == 1 && v[0] == 0) {
	co << "Yes" << en;
    } else {
	co << "No" << en;
    }
    
    return 0;
}


Measured memory_bytes: 4472
while True:
    a,b,c= input().split()
    a = int(a)
    c = int(c)
    if b == "+":
        print(a + c)
    elif b == "-":
        print(a - c)
    elif b == "*":
        print(a * c)
    elif b == "/":
        print(a // c)
    elif b == "?":
        break




Measured memory_bytes: 5596
N, X = map(int, input().split())
x = list(map(int, input().split()))
y = [abs(x[i]-X) for i in range(N)]

#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

ans = y[0]
for i in y:
    ans = gcd(i, ans)
print(ans)

Measured memory_bytes: 63256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll mpow(ll m, ll p){
  ll power = m;
  ll res = 1;
  while(p>0){
    if(p&1)
      res = res*power;
    power = power*power;
    p /= 2;
  }
  return res;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n,k;
  cin>>n>>k;

  vll a(n);
  REP(i,n)cin>>a[i];
  vll remind(n+1);
  REP(i,n)remind[i+1]=remind[i]+a[i];

  vll sum(n*(n+1)/2);
  ll cur=0;
  for(ll i=0; i<n; i++){
    for(ll j=i+1; j<=n; j++){
      sum[cur]=remind[j]-remind[i];
      cur++;
    }
  }


  ll max_p=40;
  ll now=0;
  ll base=pow(2,40);
  for(ll i=max_p; i>=0; i--){
    ll cnt=0;
    REP(j,sum.size()){
      if(((now+base)&sum[j])==now+base)
          cnt++;
    }

    if(k<=cnt)
      now+=base;
    base/=2;
  }

  cout<<now<<endl;
}



Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
typedef long long int ll;
typedef long double ld;
const ll mod = 1e9+7;
const ll INF = 1e18;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

class mint {
public:
    long long x;
    constexpr mint(long long x=0) : x((x%mod+mod)%mod) {}
    constexpr mint operator-() const { 
      return mint(-x);
    }
    constexpr mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    constexpr mint inv() const {
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
};
ostream& operator<<(ostream& os, const mint& m){
    os << m.x;
    return os;
}



int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll x, y;
  cin >> x >> y;

  if ((x+y)%3 != 0) {
    cout << 0 << '\n';
    return 0;
  }

  ll a = (2*y-x)/3;
  ll b = (2*x-y)/3;
  if (a < 0 || b < 0) {
    cout << 0 << '\n';
    return 0;
  }
  mint ans = 1;

  rep(i,a+b) {
    ans *= (i+1);
  }
  rep(i,a) {
    ans /= (i+1);
  }
  rep(i,b) {
    ans /= (i+1);
  }

  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3692
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int a= sc.nextInt();
        int b= sc.nextInt();
        if(a<b){
            System.out.println("a < b");
        }else  if(a>b){
            System.out.println("a > b");
            }else{
                System.out.println("a == b");
            }
        }
    }



Measured memory_bytes: 26288
import java.util.Arrays;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[3*n];

		for (int i = 0; i < 3*n; i++) {
			a[i] = scanner.nextInt();
		}
		Arrays.sort(a);
		long ans = 0;
		for (int i = 3*n-2; i >= n; i-=2) {
			ans+= a[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 91760
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve(n):
    lis = []
    for i in range(n):
        l = input().split()
        p,a,b,c,d,e,f,s,m = [int(i) for i in l[1:]]
        l = l[0]
        lis.append(((f*s*m-p)/(a+b+c+(d+e)*m),l))
    lis.sort(key = lambda x:(-x[0],x[1]))
    for i, j in lis:
        print(j)
    print("#")
    return

#Solve
if __name__ == "__main__":
    while 1:
        n = I()
        if n == 0:
            break
        solve(n)



Measured memory_bytes: 8192
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    constexpr auto M = 2;
    int n;
    cin >> n;

    array<vector<int64_t>, M> a;
    for (auto&& aa : a) {
        aa.resize(n);
        for (auto&& aaa : aa) {
            cin >> aaa;
        }
    }

    int64_t score = a[0][0];
    for (auto aa : a[1]) {
        score += aa;
    }

    int64_t max_score = score;
    for (auto i : irange(1, n)) {
        score = score - a[1][i-1] + a[0][i];
        max_score = max(max_score, score);
    }

    cout << max_score << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	string s1, s2,s3; cin >> s1 >> s2 >> s3;
	stringstream ss; 
	s1[0] ^= 0x20;
	s2[0] ^= 0x20;
	s3[0] ^= 0x20;
	ss << s1[0] << s2[0] << s3[0];
	cout << ss.str() << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

void solve() {
    string s;
    read(s);
    
    int l = -1, r = -1;
    
    FOR(s.size()) {
        if (s[i] == 'A' && l == -1) {
            l = i;
        }
        
        if (s[i] == 'Z') {
            r = i;
        }
    }
    
    print(r - l + 1);
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
//    read(tt);
    FOR(tt) {
//        write("Case #", i + 1, ": ");
        solve();
    }
    
}



Measured memory_bytes: 3840
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
int n, sum=0;
int B[100];

int main(){
  cin >> n;
  for (int i=0; i<n-1;i++){
    cin >> B[i];
  }
  for (int i=0; i<n-2; i++){
    sum+=min(B[i], B[i+1]);
  }
  sum+=B[0]+B[n-2];
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int n, m, q;
vector<int> a, b, c, d, st;
int ans;

void dfs(int i)
{
	int j = 1; 
	while (j <= m)
	{
		if (i == 0 || st[i - 1] <= j)
		{
			st[i] = j;
			if (i == n - 1)
			{
				int sum = 0;
				rep(i, q)
				{
					if (st[b[i]] - st[a[i]] ==  c[i])
						sum += d[i];
				}
				ans = max(ans, sum);
			}
			else
				dfs(i + 1);
		}
		j++;
	}
}

signed main(void)
{
	cin >> n >> m >> q;
	a = b = c = d = vector<int>(q);
	st = vector<int>(n);
	rep(i, q) 
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}
	ans = 0;
	dfs(0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3640
n = int(input())
s = input()

if n % 2 != 0:
	print("No")
else:
	flag = 1
	for i in range(n//2):
		if s[i] != s[i+n//2]:
			flag = 0
#			print(i)
	if flag == 1:
		print("Yes")
	else:
		print("No")

Measured memory_bytes: 2940
import java.util.*;

public class Main {
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int dam[] = new int[n];
        int sum = 0;
        for (int i=0; i<n; i++){
            dam[i] = sc.nextInt();
            sum += dam[i];
        }


        int mt[] = new int[n];

        for (int i=0; i<n; i++){
            if (i%2==0){
                mt[0] += dam[i];
            }else{
                mt[0] -= dam[i];
            }
        }

        for (int i=0; i<n-1; i++){
            mt[i+1] = dam[i]*2 - mt[i];
        }

        for (int i=0; i<n; i++){
            System.out.print(mt[i]+" ");
        }
    }
}


Measured memory_bytes: 63624
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define ssd ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>


int main()
{
	ssd
	#define task "TASK"
	 //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    int x,t;
    float n;
    cin>>n>>x>>t;
    cout<<fixed<<((int)(ceil(n/x)))*t<<endl;

	return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;


int main() {
    int a,b,k;
    cin>>a>>b>>k;
    for (int i = a; i <b+1; ++i) {
        if(i-a<k || b-i<k)cout<<i<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>

using namespace std;

int main(){
    int n;
    cin>>n;
    int a[n];

    int counter1=0,counter2=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    while(true){
        for(int i=0;i<n;i++){    
            if(a[i]%2==0){
                a[i]/=2;
                counter2++;
                i=n-1;
            }
            
        }
        
        if(counter2==0){
            cout<<counter1<<endl;
            return 0;
        }else{
            counter2=0;
            counter1++;
        }
    }

}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    main();    
});

function readline() {
    return inputString[currentLine++];
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = parseInt(a[i]);

    return a;
}

function main(){
    let [n,k] = ti(readline().split(' '));
    let h = ti(readline().split(' '));

    let dp = new Array(n);
    dp.fill(999999999999999);
    dp[0] = 0;
    for(let i = 0; i < n; i++){
        for(let j = 1; j < k+1; j++){
            if(i-j >= 0)
                dp[i] = Math.min(dp[i], Math.abs(h[i]-h[i-j]) + dp[i-j]);
            else
                break;
        }
    }

    console.log(dp[n-1]);
}

Measured memory_bytes: 41044
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,a,b) for(int i(a);i<b;i++)
#define rep(i,n) for(int i(0);i<n;i++)
#define fast  ios_base::sync_with_stdio(0); cin.tie(0);
#define pres(x) cout<<fixed; cout<<setprecision(x);
#define open freopen("input.txt","r",stdin) ; freopen("output.txt","w",stdout);
#define watch(x) cout<<(#x)<<" is "<<x<<"\n";
#define mod 1000000007

int s(int a, int b, int c){
	return min(a, min(b,c));
}

int l(int a, int b, int c){
	return max(a, max(b,c));
}

int32_t main(){
	
	fast;
	//open;

	int n, ans=0;
	cin>>n;
	int array[n];
	rep(i,n)cin>>array[i];
	f(i,1,n-1){
		if((array[i] != s(array[i-1], array[i], array[i+1]))&&(array[i]!=l(array[i-1], array[i], array[i+1])))ans++;
	}
	cout<<ans;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, string> pis;

int n, k[1010], r[1010];
string m[1010];
vector<pis> G[1010];

void dfs(int s, int d) {
  for (int i = 0; i < d; i++) {
    cout << ".";
  }
  cout << m[s - 1] << endl;
  for (int i = 0; i < G[s].size(); i++) {
    dfs(G[s][i].first, d + 1);
  }
}

int main(void) {
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> k[i] >> m[i];
    G[k[i]].push_back(pis(i + 1, m[i]));
  }

  dfs(1, 0);

  return 0;
}


Measured memory_bytes: 3416
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl

using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
//const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;



void Main(){
  ll x, y, a, b;
  bool ans = true;
  cin >> x >> y;
  if(y%2 != 0) ans = false;
  a = x*2 - y/2;
  b = y/2 - x;
  if(a < 0 || b < 0 || a > x || b > x) ans = false;

  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main()
{
	cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();

  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define _GLIBCXX_DEBUG
const int INF=1e15;

signed main(){
    string A,B,C;cin>>A>>B>>C;
    int i=0;
    while(true){

      	if(i==0){
           if(A.size()==0){
                cout<<"A"<<endl;
                break;
            }  
          char c=A[0];
            A=A.substr(1);
           
            if(c=='a')i=0;
            if(c=='b')i=1;
            if(c=='c')i=2;
          	continue;
        }
        if(i==1){
          if(B.size()==0){
                cout<<"B"<<endl;
                break;
            }  
          char c=B[0];
            B=B.substr(1);
            
            if(c=='a')i=0;
            if(c=='b')i=1;
            if(c=='c')i=2;
          	continue;
        }
        if(i==2){
                      if(C.size()==0){
                cout<<"C"<<endl;
                break;
            }
            char c=C[0];
            C=C.substr(1);

            if(c=='a')i=0;
            if(c=='b')i=1;
            if(c=='c')i=2;
          continue;
        }
    }
}

Measured memory_bytes: 256
output = []
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    count = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            for k in range(j+1, n):
                if i + j + k + 3 ==x:
                    count += 1
    output.append(count)

for o in output:
    print(o)


Measured memory_bytes: 5600
#include<stdio.h>
#include<algorithm>
using namespace std;
int ABS(int a){return max(a,-a);}
int main(){
  int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
  if((ABS(a-b)<=d&&ABS(b-c)<=d)||ABS(a-c)<=d)printf("Yes\n");else printf("No\n");
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;


signed main(){
	int A,B;
	cin>>A>>B;
	out(A*B);
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define lli long long int

lli dp[100005];

int main()
{
lli n,w,V=0;
cin>>n>>w;
vector<vector<lli> > v(n,vector<lli> (2));
for(lli i=0;i<n;i++)
{
cin>>v[i][0]>>v[i][1];
V+=v[i][1];
}
//cout<<V<<endl;
for(lli i=0;i<=V;i++)
dp[i]=INT_MAX;
dp[0]=0;
for(lli i=1;i<=n;i++)
{
    for(lli j=V;j>=v[i-1][1];j--)
    dp[j]=min(dp[j],dp[j-v[i-1][1]]+v[i-1][0]);
}
for(lli j=V;j>=0;j--)
{
    if(dp[j]<=w)
    {
        cout<<j<<endl;
        break;
    }
}
return 0;
}

Measured memory_bytes: 1024
S = list(str(input()))
for i in range(len(S)):
    S[i] = int(S[i])

lead = S.pop(0)
n = len(S)
k = 7-lead
l = ['=7']

def dfs(i, sum):
    if i == n:
        return sum == k
    if dfs(i + 1, sum + S[i]):
        l.insert(0, '+')
        return True
    if dfs(i + 1, sum - S[i]):
        l.insert(0, '-')
        return True
    return False

if dfs(0, 0):
    S.insert(0, lead)
    for i in range(n+1):
        print(S[i], end='')
        print(l[i], end='')
    print('')    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <assert.h>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  long long sum = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    sum += a[i];
  }
  long long tmp = 0, ans = 1e16;
  for (int i = 0; i < n - 1; i++)
  {
    tmp += a[i];
    sum -= a[i];
    ans = min(ans, abs(tmp - sum));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int D, N;
    cin >> D >> N;
    if (N == 100) N += 1;
    if (D == 0) {
        cout << N << endl;
    } else if (D == 1) {
        cout << N*100 << endl;
    } else if (D == 2) {
        cout << N*10000 << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int sum=0;
    if(n>1)
    {
        for(int i=1;i<n;i++)
        {
            sum+=i;
        }
   }
   if(m>1)
   {
     for(int i=1;i<m;i++)
        {
            sum+=i;
        }
   }
   cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rp(p) for(int k = 0; k < p; k++)
#define it(q) for(auto j = q.begin(); j != q.end(); j++)
#define s string 
#define vi vector<int>
#define vs vector<string>
#define pb push_back
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long int ll;

bool isSorted(int* a, int n){
	for(int i = 0; i < n-1; i++){
		if(a[i] > a[i+1]){
			return false;
		}
	}
	return true;
}

int main(){
	FIO;
	ll d,s,t;
	cin >> d;
	cin >> t;
	cin >> s;
	if(s*t < d){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
}


Measured memory_bytes: 3608
#include <cstdio>

int main()
{
  int n;
  scanf("%d", &n);
  for (int i = 0; i <= n / 7; ++i)
  {
    if ((n - 7 * i) % 4 == 0)
    {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}

Measured memory_bytes: 128