akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node {
  int key;
  struct node *parent, *left, *right;
};

struct node *tree, *z;

void insert(struct node *T, struct node *z);
struct node *find(int key);
void delete(int key);
void inorder(struct node *p);
void preorder(struct node *p);

int main(int argc, char*argv[])
{
  int m, i, key;
  char cmd[6 + 1];

  tree = NULL;

  scanf("%d", &m);

  for (i = 0; i < m; i++) {
    scanf("%s", cmd);

    if (!strcmp(cmd, "insert")) {
      z = (struct node *)malloc(sizeof(struct node));
      scanf("%d", &(z->key));
      z->parent = NULL;
      z->left = NULL;
      z->right = NULL;
      insert(tree, z);
    } else if (!strcmp(cmd, "print")) {
      inorder(tree);
      printf("\n");
      preorder(tree);
      printf("\n");
    } else if (!strcmp(cmd, "find")) {
      scanf("%d", &key);
      if (find(key) != NULL) printf("yes\n");
      else printf("no\n");
    } else if (!strcmp(cmd, "delete")) {
      scanf("%d", &key);
      delete(key);
    }
  }

  return 0;
}

void insert(struct node *T, struct node *z)
{
  struct node *x, *y;

  y = NULL;
  x = tree;
  while (x != NULL) {
    y = x;
    if (z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if (y == NULL) tree = z;
  else if (z->key < y->key) y->left = z;
  else y->right = z;
}

struct node *find(int key)
{
  struct node *x = tree;

  if (x == NULL) {
    return NULL;
  }
  
  while (x != NULL) {
    if (x->key == key) {
      return x;
    } else if (x->key < key) x = x->right;
    else x = x->left;
  }
  return NULL;
}

void delete(int key)
{
  struct node *x = find(key);
  struct node *y;

  if (x == NULL) {
    printf("error\n");
    return;
  }

  if (x->left == NULL && x->right == NULL) {
    if (x->parent->key < x->key) x->parent->right = NULL;
    else x->parent->left = NULL;
    free(x);

  } else if (x->left != NULL && x->right != NULL) {
    y = x->right;
    while (y->left != NULL) y = y->left;
    x->key = y->key;
    if (y->right != NULL) {
      if (y->parent->key == y->key) y->parent->right = y->right;
      else y->parent->left = y->right;
      y->right->parent = y->parent;
    } else {
      if (y->parent->key == y->key) y->parent->right = NULL;
      else y->parent->left = NULL;
    }
    free(y);

  } else {
    if (x->left != NULL) {
      if (x->parent->key < x->key) x->parent->right = x->left;
      else x->parent->left = x->left;
      x->left->parent = x->parent;
    } else {
      if (x->parent->key < x->key) x->parent->right = x->right;
      else x->parent->left = x->right;
      x->right->parent = x->parent;
    }
    free(x);
  }
}

void inorder(struct node *p)
{
  if (p->left != NULL) inorder(p->left);
  printf(" %d", p->key);
  if (p->right != NULL) inorder(p->right);
}

void preorder(struct node *p)
{
  printf(" %d", p->key);
  if (p->left != NULL) preorder(p->left);
  if (p->right != NULL) preorder(p->right);
}

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

#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define FOR(i,l,r) for(long long i=l; i<r; i++)
#define FOR_REV(i,r,l) for(long long i=r; i>=l; i--)
#define pb push_back
#define mp make_pair

int main()
{
    int a,b,c;
    cin>>a>>b>>c;

    if (a==b && b!= c)
    {
        cout<<"Yes"<<endl;
    }
    else if (a==c && b != c)
    {
        cout<<"Yes"<<endl;
    }
  	else if (b==c && a != c)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 09/26/20 20:43:51
// -----------------------------------

#include <bits/stdc++.h>
#include <atcoder/all>

namespace {
using namespace std;
using ll = long long;

using mint = atcoder::modint998244353 ;
struct S {
  int sz;
  mint v;
};
constexpr int MAX = 2e5;
vector<mint> P(MAX+1);
vector<mint> O(MAX+1);
S op(S a, S b) { return {a.sz+b.sz, a.v * P[b.sz] + b.v}; }
S unit() {return {0, 0};}
int id() {return 0;}
S map(int f, S s) {
  if (f == id())
    return s;
  return {s.sz, O[s.sz]*f};
}
int comp(int f, int g) {return f==id() ? g : f;}
using Ruq = atcoder::lazy_segtree<S, op, unit, int, map, comp, id>;

void init() {
  P[0] = 1;
  for (int i = 1; i <= MAX; i++)
    P[i] = P[i-1]*10;
  O[0] = 0;
  for (int i = 1; i <= MAX; i++) {
    O[i] = O[i-1] + P[i-1];
  }
}
}

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

  init();
  int n,q; cin>>n>>q;
  Ruq ruq(n);
  for (int i = 0; i < n; i++)
    ruq.set(i, {1,1});
  while (q--) {
    int l,r,d; cin>>l>>r>>d; l--; r--;
    ruq.apply(l, r+1, d);
    cout << ruq.all_prod().v.val() << endl;
  }

  return 0;
}


Measured memory_bytes: 11396
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    int N, Q;
    scan(N, Q);
    auto uf = dsu(N);
    foreach (_; 0 .. Q)
    {
        int t, u, v;
        scan(t, u, v);
        if (t == 0)
        {
            uf.merge(u, v);
        }
        else
        {
            writeln(uf.same(u, v) ? 1 : 0);
        }
    }
}

struct dsu
{
public:
    this(int n)
    {
        _n = n, parent_or_size = new int[](n);
        parent_or_size[] = -1;
    }

    int merge(int a, int b)
    {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        int x = leader(a), y = leader(b);
        if (x == y)
            return x;
        if (-parent_or_size[x] < -parent_or_size[y])
        {
            auto tmp = x;
            x = y;
            y = tmp;
        }
        parent_or_size[x] += parent_or_size[y];
        parent_or_size[y] = x;
        return x;
    }

    bool same(int a, int b)
    {
        assert(0 <= a && a < _n);
        assert(0 <= b && b < _n);
        return leader(a) == leader(b);
    }

    int leader(int a)
    {
        assert(0 <= a && a < _n);
        if (parent_or_size[a] < 0)
            return a;
        return parent_or_size[a] = leader(parent_or_size[a]);
    }

    int size(int a)
    {
        assert(0 <= a && a < _n);
        return -parent_or_size[leader(a)];
    }

    int[][] groups()
    {
        auto leader_buf = new int[](_n), group_size = new int[](_n);
        foreach (i; 0 .. _n)
        {
            leader_buf[i] = leader(i);
            group_size[leader_buf[i]]++;
        }
        auto result = new int[][](_n);
        foreach (i; 0 .. _n)
            result[i].reserve(group_size[i]);
        foreach (i; 0 .. _n)
            result[leader_buf[i]] ~= i;
        int[][] filtered;
        foreach (r; result)
            if (r.length != 0)
                filtered ~= r;
        return filtered;
    }

private:
    int _n;
    int[] parent_or_size;
}


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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define str string
#define s_vec(data,name,vertical,horizontal) vector<vector<(data)>> (name)((vertical),vector<(data)>((horizontal)));


int main(){
    ll n,k;
    cin>>n>>k;

    vector<ll> a(n);
    vector<int> b;

    rep(i,n){
        cin>>a.at(i);
    }

    sort(a.begin(),a.end());


    ll j=a.at(0);
    int co=0;
    rep(i,n){
        if(j!=a.at(i)){
            j = a.at(i);
            b.push_back(co);
            co=1;
        }else{
            co++;
        }
        if(i==(n-1)){
            b.push_back(co);
        }
    }

    sort(b.begin(),b.end());

    ll stn;
    if(b.size()>k){
        stn = b.size() - k;
    }else{
        stn = 0;
    }

    ll ans = 0;
    for(int i=0;i<stn;i++){
        ans += b.at(i);
    }

    cout<<ans<<endl;


}

Measured memory_bytes: 2936
#include<stdio.h>
int main()
{
    int N;
    int a[102];
    scanf("%d",&N);
    for(int i=0; i<N; i++){
        scanf("%d",&a[i]);
    }
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            if(a[i]<a[j]){
                int tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }
        }
    }
    int p[2];
    p[0] = p[1] = 0;
    for(int i=0; i<N; i++){
        p[i%2] += a[i];
    }
    printf("%d\n",p[0]-p[1]);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        string a, b;
        cin >> a >> b;
        if(a == "0")
            return 0;

        vector<bool> num(10, false);
        for(int i=0; i<4; ++i)
            num[a[i]-'0'] = true;

        int ret1 = 0;
        int ret2 = 0;
        for(int i=0; i<4; ++i){
            if(a[i] == b[i])
                ++ ret1;
            else if(num[b[i]-'0'])
                ++ ret2;
        }

        cout << ret1 << ' ' << ret2 << endl;
    }
}

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

#define N 200020

typedef long long ll;
int n, a[N<<1];
ll k;

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

int c[N];
int vis[N];

int main() {
	scanf("%d%lld", &n, &k);
	for (int i = 0; i < n; i ++) scanf("%d", &a[i]);
	for (int i = 0; i < n; i ++) a[n+i] = a[i];
	for (int i = 2 * n - 1; i >= 0; i --) {
		if (i < n) {
			g[i] = b[a[i]] + 1 - i;
			to[i] = (b[a[i]] + 1) % n;
		}
		b[a[i]] = i;
	}
	c[1] = 0;
	vis[0] = 1;
	int st, d;
	for (int i = 2;; i ++) {
		c[i] = to[c[i-1]];
		if (vis[c[i]]) {
			st = vis[c[i]];
			d = i - st;
			break;
		}
		vis[c[i]] = i;
	}
	ll up = k * n;
	ll p = 1;
	ll cur = 0;
	for (p = 1; p < st; p ++) {
		assert(cur % n == c[p]);
		if (cur + g[c[p]] >= up) break;
		cur += g[c[p]];
	}
	if (p == st) {
		ll bl = 0;
		for (ll i = st; i < st + d; i ++) {
			bl += g[c[i]];
		}
		ll step = (up - 1 - cur) / bl;
		cur += bl * step;
	}
	for (; ; p ++) {
		if (cur + g[c[p]] >= up) break;
		cur += g[c[p]];
	}
	assert(p <= st + d);
	assert(cur < up);
	memset(vis, 0, sizeof vis);
	int en = 0;
	for (ll i = cur; i < up; i ++) {
		int j = i % n;
		if (!vis[a[j]]) b[++en] = a[j], vis[a[j]] = en;
		else {
			int oen = en;
			en = vis[a[j]] - 1;
			for (int k = oen; k > en; k --) vis[b[k]] = 0;
		}
	}
	for (int i = 1; i <= en; i++) printf("%d ", b[i]);
}


Measured memory_bytes: 6912
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    s = input()
    prev = s[0]
    count = 1

    for i in range(1, n):
        cur = s[i]

        if cur != prev:
            count += 1
            prev = cur

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<stdio.h>
int main()
{
	
	long long int n,c;

	char str[5];
		scanf("%s",str);
	
	if((str[0]^str[1])==0 || (str[1]^str[2])==0 || (str[2]^str[3])==0 )
		printf("Bad\n");
	else
		printf("Good\n");

	
	return 0;
}






Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
  int a,b;

  cin >>a>>b;
  if(a>b){
    cout<<"a > b"<<endl;}
  else if(a<b){
    cout<<"a < b"<<endl;}
  else{cout<<"a == b"<<endl;}
  return 0;

}

Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
	string s;
	cin>>s;
	if(s[s.size()-1]=='s')s+="e";
	cout<<s+'s';
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>

using namespace std;

int hrpe[100005];

int main() {
	int n;
	cin >> n;
	for (int i=0;i<n;i++) cin >> hrpe[i];
	sort (hrpe, hrpe+n);
	int zadnji = -1;
	for (int i=0;i<n;i++) {
		int b = hrpe[i]-1;
		int u = n-i-1;
		if ((b+u) % 2 == 0) {
			if (u <= (b+u)/2) {
				if (zadnji == -1) {
					cout << "Second";
					break;
				}
				else if (hrpe[i-1] != hrpe[i]) {
					cout << "Second";
					break;
				}
				else if (!zadnji) {
					cout << "Second";
					break;
				}
			}
		}
		else {
			if (u <= (b+u)/2+1) {
				if (zadnji == -1) {
					cout << "First";
					break;
				}
				else if (hrpe[i-1] != hrpe[i]) {
					cout << "First";
					break;
				}
				else if (zadnji) {
					cout << "First";
					break;
				}
			}
		}
		if (i != 0) {
			if (hrpe[i-1] != hrpe[i]) {
				zadnji = (b+u)%2;
			}
		}
		else {
			zadnji = (b+u) % 2;
		}
	}
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>

int main()
{
    int N, i, j, k, l, c, b, count = 0;
    double a1, a2;
    scanf("%d", &N);
    for (i = 1; i <= N; i++)
    {
        count = 0;
        for (j = 1; j <= 110; j++)
        {
            for (k = 1; k <= 110; k++)
            {
                b = j + k;
                c = -1 * i + j * j + k * k + j * k;
                a1 = (-1 * b + sqrt(b * b - 4 * c)) / 2;
                a2 = (-1 * b - sqrt(b * b - 4 * c)) / 2;
                if (ceil(a1) == floor(a1) && a1 >= 1)
                {
                    count++;
                }
                if (ceil(a2) == floor(a2) && a2 >= 1)
                {
                    count++;
                }
            }
        }
        printf("%d\n", count);
    }
    return 0;
}

Measured memory_bytes: 2180
N=int(input())

import sys

for h in range(1,3501):
    for n in range(h,3501):
        a=(h*n*N)
        b=(4*h*n-(n+h)*N)
        if b==0:
            continue

        
        #w=int(w)

        #if w<h:
        #    break

        #print(h,n,w)
        #print(a,b)
        if a%b==0:
            w = a/b
            if N*(n*w+h*w+h*n)!=4*n*w*h:
                continue
            #print(w)
            if w>0:
                w=int(w)
                print(h,n,w)
                '''

                print(4/N)
                print(1/h+1/n+1/w)
                print(a,b)
                print(a/b)
                '''
                sys.exit()


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
ll sz(string &s){ return (ll)s.size(); }
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }



const ll MOD = 1e9+7;
 
template <ll MOD>
struct modint{
    ll x;
    modint() : x(0) {}
    modint(ll a): x((a % MOD + MOD) % MOD) {}
    
    
 
    bool operator!() const{return !x;}
 
    bool operator<(const modint &a) const{
        modint res(*this);
        return res.x < a.x;
    }
    
    bool operator>(const modint &a) const{
        modint res(*this);
        return res.x > a.x;
    }
 
    modint &operator+=(const modint &a){
        if((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator-=(const modint &a){
        if((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator*=(const modint &a){
        (x *= a.x) %= MOD;
        return *this;
    }
 
    modint &operator/=(const modint &a){
        *this *= a.inv();
        return *this;
    }
 
    modint &operator%=(const modint &a){
        x %= a.x;
        return *this;
    }
 
    modint operator-() const{ return modint(-x); }
 
    modint operator+(const modint &a) const{ return modint(*this) += a; }
    modint operator-(const modint &a) const{ return modint(*this) -= a; }
    modint operator*(const modint &a) const{ return modint(*this) *= a; }
    modint operator/(const modint &a) const{ return modint(*this) /= a; }
    modint operator%(const modint &a) const{ return modint(*this) %= a; }
    bool operator==(const modint &a) const{ return x == a.x; }
    bool operator!=(const modint &a) const{ return x != a.x; }
 
 
    modint pow(ll n) const{
        modint res(1), a(x);
        while(n > 0){
            if(n & 1) res *= a;
            a *= a;
            n /= 2;
        }
        return res;
    }
 
    modint inv() const{
        return this->pow(MOD-2);
    }
 
    friend ostream &operator<<(ostream &os, const modint &m){
        return os << m.x;
    }
 
    friend istream &operator>>(istream &is, modint &m){
        ll t;
        is >> t;
        m = modint<MOD>(t);
        return (is);
    }
    
    static ll get_mod(){ return MOD; }
};
using mint = modint<MOD>;

int main(){
    ll s;
    cin >> s;
    mint fact[s+1] = {};
    fact[0] = 1;;
    rep(i,1,s+1) fact[i] = fact[i-1]*i;
    
    mint ans = 0;
    rep(i,1,s/3+1){
        ans += fact[s-3*i+i-1]/fact[i-1]/fact[s-3*i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3544
from operator import mul
from functools import reduce


def comb(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    return reduce(mul, range(n, n-r, -1))//reduce(mul, range(1, r+1))


S = input()
ans = 0
for i in range(len(S)):
    for j in range(i, len(S)):
        s = 0
        s2 = 0
        for k in range(i):
            s += comb(i-1, k)
        for k in range(len(S)-j-1):
            s2 += comb(len(S)-j-2, k)
        ans += int(S[i:j+1])*max(s, 1)*max(s2, 1)
print(ans)


Measured memory_bytes: 38512
# AGC023Aたらいう地獄みたいに難しいやつのさらに上を行く地獄

n, m = map(int, input().split())
arr = list(map(int, input().split()))
b = [0]
d = {0: 1}
for i in range(n):
    b.append(b[i] + arr[i])
    if b[i + 1] % m in d:
        d[b[i + 1] % m] += 1
    else:
        d[b[i + 1] % m] = 1
ans = 0
for _, v in d.items():
    ans += (v * (v - 1)) // 2
print(ans)

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

int main() {
	int N;

	cin >> N;

	if (N == 1) {
		cout << "Hello World" << endl;
	} else if (N == 2) {
		int A, B;

		cin >> A >> B;

		cout << A + B << endl;
	}

	return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Lamps
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

/* global variables */

int as[2][MAX_N + 1];

/* subroutines */

void printv(int n, int v[]) {
  for (int i = 0; i < n; i++) {
    printf("%d", v[i]);
    putchar(i + 1 < n ? ' ' : '\n');
  }
}

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", as[0] + i);
  //printf("%d: ", 0); printv(n, as[0]);

  int cur = 0, nxt = 1;
  for (int i = 0; i < k; i++) {
    memset(as[nxt], 0, sizeof(as[nxt]));

    for (int j = 0; j < n; j++) {
      as[nxt][max(0, j - as[cur][j])]++;
      as[nxt][min(n, j + as[cur][j] + 1)]--;
    }
    for (int j = 0; j < n; j++) as[nxt][j + 1] += as[nxt][j];
    //printf("%d: ", i + 1); printv(n, as[nxt]);

    swap(cur, nxt);

    bool cont = false;
    for (int j = 0; j < n; j++)
      if (as[cur][j] < n) cont = true;
    if (! cont) break;
  }

  printv(n, as[cur]);
  return 0;
}


Measured memory_bytes: 4788
#include <cstdio>
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(){
	int M1,D1,M2,D2;

	scanf("%d %d",&M1,&D1);
	scanf("%d %d",&M2,&D2);

	if(M1==M2){
		printf("0");
	}else{
		printf("1");
	}
	return 0;
}


Measured memory_bytes: 256
/*
３つの整数 
a
、
b
、
c
 を読み込み、
a
 から 
b
 までの整数の中に、
c
 の約数がいくつあるかを求めるプログラムを作成してください。
 */

int main(void) {
    int x, y, n;
    
    scanf("%d %d %d", &x, &y, &n);
    
    int count = 0;
    for (int i = x; i < y + 1; ++i) {
        if (n % i == 0) {
            count++;
        }
    }
    
    printf("%d\n", count);
    
    return 0;
}


Measured memory_bytes: 2096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    string s;
    cin >> N >> s;
    
    int Red = 0;
    int Blu = 0;
    
    for (int i = 0; i < N; i++) {
        if(s[i] == 'R') Red++;
        else Blu++;
    }
    
    if (Red > Blu) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    csf <- replicateM (n-1) $ do
        [c,s,f] <- getIntList
        return (c,s,f)
    mapM_ print . map (foldl' solve 0) $ tails csf

solve t (c,s,f) = c + max s (t + ((-t) `mod` f))

Measured memory_bytes: 1020
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int n,W;

int main() {
    cin >> n >> W;
    vector<ll> w(n);
    vector<ll> v(n);
    REP(i, n){
        cin >> w[i] >> v[i];
    }
    vector<vector<ll>>  dp(W+1,vector<ll>(n+1,0));
    REP(i,n){
        REP(j,W+1){
            dp[j][i+1]=max(dp[j][i+1],dp[j][i]);
            if(j+w[i]<=W){
                dp[j+w[i]][i+1]=max(dp[j+w[i]][i],dp[j][i]+v[i]);
            }
        }
    }
    put(*max_element(all(dp[W])));
    return 0;
}




Measured memory_bytes: 82304
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
  int N;cin>>N;
  string S;cin>>S;
  long long r=0,b=0,g=0;
  long long ans=0;
  for(int i=0;i<N;i++){
    if(S[i]=='R') r++;
    else if(S[i]=='B') b++;
    else g++;
  }
  ans+=r*b*g;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      if(2*j-i<N&&S[i]!=S[j]&&S[2*j-i]!=S[i]&&S[2*j-i]!=S[j]) ans--;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
}

Measured memory_bytes: 256
A = input()
B = input()
if A == B:
    print("EQUAL")

if len(B) < len(A):
    print("GREATER")
elif len(A) < len(B):
    print("LESS")
else:
    for i in range(0, len(A)):
        if int(B[i]) < int(A[i]):
            print("GREATER")
            break
        elif int(A[i]) < int(B[i]):
            print("LESS")
            break


Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
	int count;
	int n;
	int m;
	
	while (1) {
		count = 0;
		scanf("%d", &n);
		
		if (n == 0) {
			break;
		}
		
		m = 1000 - n;
		count += m / 500;
		m %= 500;
		count += m / 100;
		m %= 100;
		count += m / 50;
		m %= 50;
		count += m / 10;
		m %= 10;
		count += m / 5;
		m %= 5;
		count += m;
		
		printf("%d\n", count);
	}
	
	return (0);
}

Measured memory_bytes: 600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

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

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            int N = Integer.parseInt(br.readLine());

            long[] lucasTmp = {2, 1};

            for (int i = 2; i < N; i++) {
                long tmp = lucasTmp[0] + lucasTmp[1];
                lucasTmp[0] = lucasTmp[1];
                lucasTmp[1] = tmp;
            }


            long ans = 0;
            if (N == 0) {
                ans = lucasTmp[0];
            } else if (N == 1) {
                ans = lucasTmp[1];
            } else {
                ans = lucasTmp[0] + lucasTmp[1];
            }

            System.out.println(ans);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,x;
    cin>>n>>a;
    x=n/a;
    if(n%a==0)
    {
        cout<<x<<endl;
    }
    else
    {
        cout<<x+1<<endl;
    }
    return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

const int maxn = 1e5 + 5;
ll dp[maxn];
ll pre1[maxn];
ll x[maxn];

int n;
ll T, E;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> E >> T;
    for(int i = 1;i <= n;i++){
        cin >> x[i];
    }
    dp[0] = 0;
    pre1[0] = dp[0] - 2 * x[1];
    int l = -1;
    for(int i = 1;i <= n;i++){
        while(l + 1 < i and 2 * (x[i] - x[l + 2]) >= T){
            l++;
        }
        dp[i] = 1e18;
        if(l >= 0)
            dp[i] = pre1[l] + 2 * x[i];
        if(l + 1 < i){
            dp[i] = min(dp[i], dp[l + 1] + T);
        }
        pre1[i] = pre1[i - 1];
        pre1[i] = min(pre1[i - 1], dp[i] - 2 * x[i + 1]);
    }
    cout << E + dp[n] << endl;
    return 0;
}


Measured memory_bytes: 2560
import copy

n=int(input())
lst=[int(input()) for i in range(n)]

ans = [max(lst)] * n

if lst.count(max(lst)) == 1:
    tmp = copy.deepcopy(lst)
    tmp.pop(lst.index(max(lst)))
    ans[lst.index(max(lst))] = max(tmp)

for l in ans:
    print(l)

Measured memory_bytes: 16092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    //ll ngroup = -1;
    
    ll m = 0;
    while(1ll*m*(m-1)/2 < N) ++m;
    if(1ll*m*(m-1)/2 != N){
        cout << "No" << endl;
        return 0;
    }
    /*
    REP(i,1,N+1){
        if(2*N == i*(i-1)){
            ngroup = i;
            break;
        }
    }
    if(ngroup == -1){
        cout << "No" << endl;
        return 0;
    }else{*/
    ll ngroup = m;
        cout << "Yes"<< endl;
        cout << ngroup << endl;
        vector<vector<ll>> v(ngroup+1);
        ll num = 1;
        rep(i,ngroup){
            REP(j,i+1,ngroup){
                v[i].push_back(num);
                v[j].push_back(num);
                num++;
            }
        }
        rep(i,ngroup){
            cout << v[i].size() << " ";
            PR(v[i],v[i].size());
        }
        /*
        cout << ngroup << endl;
        cout << ngroup -1;
        t = 1;
        REP(i,1,N+1){
            cout << " " << i;
            i += t;
            t++;
        }
        cout << endl;

        t=0;
        ll u=1;
        ll st=1;
        rep(i,ngroup-1){
            ll cur = st;
            rep(j,t){
                cout << " " << cur+j;
                u++;
            }
            cur += 
            rep(j,ngroup-1-t){
                cout << " " << cur;
                cur += u;
            }
        }
        /*
        rep(i,ngroup){
            cout << ngroup-1;
            rep(j,M-1){
                cout << " " << << endl;
                
            }
        }*/
    //}
}



Measured memory_bytes: 3200
import pprint
H, N = list(map(int, input().split()))

A, B = [0]*N, [0]*N


for i in range(N):
    a, b = list(map(int, input().split()))
    A[i], B[i] = a, b

maxDamage = H + max(A)

dp = [[float("inf") for _ in range(maxDamage+1)] for _ in range(N+1)]
dp[0][0] = 0

for i in range(N):
    for j in range(maxDamage+1):

        if j < A[i]:
            dp[i+1][j] = dp[i][j]

        else:
            res1 = dp[i][j]
            res2 = dp[i+1][j - A[i]] + B[i]

            dp[i+1][j] = min(res1, res2)

# pprint.pprint(dp)
print(min(dp[N][H:]))


Measured memory_bytes: 241100
s = input()
t = input()

dic = {}
for i in range(len(s)):
    if s[i] in dic:
        dic[s[i]].append(i)
    else:
        dic[s[i]] = [i]
        
def f(L, u, l, x):
    if L[-1] <= x:
        return -1
    if u-l < 2:
        if L[l] > x:
            return l
        else:
            return u
    m = (u+l)//2
    if L[m] > x:
        return f(L, m, l, x)
    else:
        return f(L, u, m, x)
    
ans = 0
c = 0 #１ステップ前に考察した文字がsの前から何番目か
for i in range(len(t)):
    if t[i] not in dic:
        ans = -1
        break
    idx = f(dic[t[i]], len(dic[t[i]])-1, 0, c-1)
#    print("idx =", idx)
    if idx < 0:
        num = dic[t[i]][0]+1
        ans += len(s)-c+num
        c = num
#        print(ans,c)
    else:
        num = dic[t[i]][idx]+1
        ans += num-c
        c = num
#        print(ans,c)
        
print(ans)

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	/*{
		string ss=s;;
		int n=sz(ss), res=0;
		while(1){
			int ps = ss.find("BW");
			if(ps==-1) break;
			swap(ss[ps],ss[ps+1]);
			res++;
		}
		cout << res << "\n";

	}*/
		
	int n=sz(s);
	ll cr=0, ans=0;
	rep(i, n){
		if(s[i]=='B'){
			cr++; continue;
		}else{
			ans += cr;
		}
	}
	
	
	
	cout << ans << "\n";
	return 0;
}


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

#define LL long long
#define DD long double

#define M 1000000007
#define INF 1e18

void setIO(string s = "") { 
  cin.sync_with_stdio(0); cin.tie(0);
  if (s.size()) s += ".in", freopen(s.c_str(), "r", stdin);
}
LL f[10][10];
int tt = 1;
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s = to_string(i);
    int size = s.size();
    int t = s[0] - '0';
    int b = s[s.size() - 1] - '0';
    f[t][b]++;
  }
  LL c = 0;
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) c += f[i][j] * f[j][i];
  }
  cout << c << endl;
}

int main() {
  setIO();
  while (tt--) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3656
while True:
    wh = list(map(int, input().split()))
    if wh[0] == 0 and wh[1] == 0:
        break
    else:
        for i in range(wh[0]):
            if i > 0:
                print()
            for j in range(wh[1]):
                print("#", end="")
    print("\n")



Measured memory_bytes: 7008
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <list>
#include <ctime>
#include <random>
using namespace::std;
 
int main(){
	int a, b; cin >> a >> b;
	if(a<=8 && b<=8) cout << "Yay!";
	else cout << ":(";
	return 0;
}

Measured memory_bytes: 384
a, b = gets.chomp.split(" ").map{|i| i.to_i}
s = gets.chomp

ok = true
for i in 0...a+b+1
  if i == a
    if s[i] != '-'
      ok = false
    end
  else
    if s[i] == '-'
      ok = false
    end
  end
end

if ok
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
#include<iostream>
void merge(int a[],int low,int high){
  using namespace std;
  /*for(int i=low;i<=high;i++){
    cout<<a[i]<<"/";
  }
  cout<<endl;*/
  if(low>=high){
    return;
  }
  int m=(low+high)/2;
  merge(a,low,m);
  merge(a,m+1,high);
  int b[high-low+1];
  int bl=0;
  /*for(int i=low;i<=high;i++){
    cout<<a[i]<<":";
  }
  cout<<endl;*/
  for(int i=low;i<=m;i++){
    b[bl++]=a[i];
  }
  bl=high-low;
  for(int i=m+1;i<=high;i++){
    b[bl--]=a[i];
  }
  /*for(int i=0;i<=high-low;i++){
    cout<<b[i]<<",";
  }
  cout<<endl;*/
  int l=0,h=high-low;
  int al=low;
  while(l<=h){
    if(b[l]>b[h]){
      a[al++]=b[h--];
    }else{
      a[al++]=b[l++];
    }
  }
}
int main(void){
  using namespace std;
  int n,k;
  cin>>n;
  cin>>k;
  int h[n];
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  /*for(int i=0;i<n-1;i++){
    int min=i;
    for(int j=i+1;j<n;j++){
      if(h[min]>h[j]){
        min=j;
      }
    }
    int tmp=h[min];
    h[min]=h[i];
    h[i]=tmp;
  }*/
  merge(h,0,n-1);
  /*for(int i=0;i<n;i++){
    cout<<h[i]<<",";
  }
  cout<<endl;*/
  long long int sum=0;
  for(int i=0;i<n-k;i++){
    sum+=h[i];
  }
  cout<<sum<<endl;
  return 0;
}


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

int main()
{
	long long n,k;
    cin>>n>>k;
    long long rem=n%k;
    long long cat=abs(rem-k);
    if(rem==0) cout<<rem<<endl;
    else
    	cout<<min(rem,cat)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

int dp[1000][1000];
string k[1000];
int main(){
	int a;
	while (cin >> a, a) {
		for (int b = 0; b < a; b++) {
			cin >> k[b];
			for (int d = 0; d < a; d++) {
				if (k[b][d] == '.')dp[b][d] = 1;
				else dp[b][d] = 0;
			}
		}
		int MAX = 0;
		for (int b = 1; b < a; b++) {
			for (int c = 1; c < a; c++) {
				if (k[b][c] == '*') { dp[b][c] = 0; continue; }
				dp[b][c] = min({dp[b-1][c-1],dp[b][c-1],dp[b-1][c]})+1;
				MAX = max(MAX, dp[b][c]);
			}
		}
		cout << MAX << endl;
	}
}

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n, k;
	cin >> n >> k;
	ll a[n+1];
	rep(i, 1, n){cin >> a[i];}
	
	ll dp[n+1][k+1];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	rep(i, 1, n){
		ll cdp[k+1];
		cdp[0] = dp[i-1][0];
		rep(j, 1, k){
			cdp[j] = cdp[j-1]+dp[i-1][j];
			cdp[j] %= MOD;
		}
		
		rep(j, 0, k){
			dp[i][j] = cdp[j];
			if(j-a[i]-1 >= 0){
				dp[i][j] += MOD-cdp[j-a[i]-1];
				dp[i][j] %= MOD;
			}
		}
	}
	
	print(dp[n][k])
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    const int MX=200005;
    ll r[MX]={};
    REP(i,n) cin>>r[i];

    ll rmn=r[0],rmx=r[1];
    ll ans = r[1]-r[0];
    FOR(i,1,n){
        ans=max(ans, r[i]-rmn);
        if(rmn>r[i]) rmn=r[i];
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4760
using System;

namespace CSharpSample01
{

	class Program
	{

		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());
			long answer = 0;

			for(int i = 1; i <= N; i++)
			{
				if(i % 3 != 0 && i % 5 != 0)
				{
					answer += i;
				}
			}

			Console.WriteLine(answer);
		}
	}
}

Measured memory_bytes: 27540
/* it was worth becoming a chemist */
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 1e5 + 5;

ll n, a[MAXN], res;

int main() {	

    cin >> n;
    for (int i = 1; i <= n; i++) {
    	cin >> a[i];
    } 
    ll l = 1;
    while (l <= n) {
    	ll r1 = l + 1, r2 = l + 1;
    	while (a[r1] >= a[r1 - 1] && r1 <= n) r1++;
    	while (a[r2] <= a[r2 - 1] && r2 <= n) r2++;
    	l = max(r1, r2);
    	res++;
    }
    cout << res;
	return 0;
}


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

int main()
{
	int a;
	char s[10];
	cin >> a >> s;
	if( a >= 3200 )
	{
		cout << s << endl;
	}else if( a < 3200 )
	{
		cout << "red" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
// https://qiita.com/e869120/items/eb50fdaece12be418faa
// https://atcoder.jp/contests/abc095/tasks/arc096_a
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;

const int INF = 1e9 + 7;

int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int n = max(X, Y);

    int res = INF;
    for (int i = 0; i <= 2 * n; i+=2) {
        int sum = i * C + A * max(0, X - i / 2) + B * max(0, Y - i / 2);
        res = min(res, sum);
    }

    cout << res << endl;

    return 0;
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9+7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

bool comp(const pair<int, int> &a, const pair<int, int> &b){
  return (a.first > b.second);
}
int main(){
  FAST();
  //Code goes past here:
  int n;
  cin >> n;

  if(n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9)
    cout << "hon\n";
  else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8)
    cout << "pon\n";
  else if(n % 10 == 3)
    cout << "bon\n";

  return 0;
}


Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

class Main {
    // static {
    //     try {
    //         System.setOut(new PrintStream(new File("output.txt")));
    //         new File("input.txt").createNewFile();
    //         System.setIn(new FileInputStream(new File("input.txt")));
    //     } catch (Exception e) {
    //         e.printStackTrace();
    //     }
    // }
    static FastReader fastReader = new FastReader();
    static BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out));
    static StringBuffer stringBuffer = new StringBuffer();

    public static void main(String[] args) throws Exception {
        try {
            // int testCases = fastReader.nextInt();
            int testCases=1;
            while (testCases-- > 0) {
                int n=fastReader.nextInt();
                int k=fastReader.nextInt();
                int arr[]=new int[n];
                for(int i=0;i<n;i++){
                    arr[i]=fastReader.nextInt();
                }
                int dp[]=new int[n];
                dp[0]=0;
                for(int i=1;i<n;i++){
                    int min=Integer.MAX_VALUE;
                    for(int j=i-k;j<i;j++){
                        if(j>=0)
                        min=Math.min(min,dp[j]+Math.abs(arr[i]-arr[j]));
                    }
                    dp[i]=min;
                }
                System.out.println(dp[n-1]);
            }
            bufferedWriter.write(stringBuffer.toString());
            bufferedWriter.flush();
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 44376
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		double n = scan.nextInt();
		double m = scan.nextInt();
		double d = scan.nextInt();
		scan.close();
		if(d == 0) {
			double ans = (m - 1) / n;
			System.out.printf("%1.6f",ans);
		}else {
			double ans = 2 * (m - 1)*(n -d) / (n * n);
			System.out.printf("%1.6f",ans);
		}

	}
}

Measured memory_bytes: 22996
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

#a = list(map(int, input().split()))

n = int(input())
a = list(map(int, input().split()))

a.sort()

ans = "YES"
for i in range(n-1):
    if(a[i] == a[i+1]):
        ans ="NO"
print(ans)


















Measured memory_bytes: 112208
#include <bits/stdc++.h>
#define repeat(i, n) for(int (i) = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	string S;
	cin >> S;
	vector<int> result(S.length(), 0);

	int pos = 0, right_count, left_count;
	repeat(i, S.length()) {
		string a = S.substr(i, 1);
		pos++;
		if (a == "R") continue;

		pos -= 1; // `L`
		if (pos < 1) continue;

		// count RL of RRRRL
		result[i-1] += 1; // R
		pos -= 1; // `R`
		if (pos < 1) continue;

		// count other strings
		right_count = pos / 2;
		left_count = pos - right_count;

		result[i] += left_count;
		result[i-1] += right_count;

		pos = 0;
	}

	pos = 0;

	for(int i = S.length() - 1; i >= 0; i--) {
		string a = S.substr(i, 1);
		pos++;
		if (a == "L") continue;

		pos -= 1;	// `R`
		if (pos < 1) continue;

		// count RL of RLLLL
		result[i+1] += 1; // L
		pos -= 1;// L
		if (pos < 1) continue;

		if (pos < 1) continue;

		// count other strings
		left_count = pos / 2;
		right_count = pos - left_count;

		result[i] += right_count;
		result[i+1] += left_count;

		pos = 0;
	}

	repeat(i, S.length()) {
		cout << result[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<cstring>
using namespace std;
 
int main(){

  int a, b;
  cin >> a >> b;

  if((a*b)%2==0){
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }

  return 0;
}

Measured memory_bytes: 768
s = gets.chomp.split("")
s << "T"
x, y = gets.split.map(&:to_i)
t_count = 0
f_count = 0
x_moves = []
y_moves = []
s.each do |c|
  if c == "F"
    f_count += 1
  else
    t_count += 1
    if t_count == 1
      x -= f_count
    elsif t_count.even?
      y_moves << f_count if f_count > 0
    else
      x_moves << f_count if f_count > 0
    end
    f_count = 0
  end
end
x_moves.sort!
y_moves.sort!

x_must_deduced, x_mod = ((x_moves.inject(:+) || 0) - x.abs).divmod(2)
y_must_deduced, y_mod = ((y_moves.inject(:+) || 0) - y.abs).divmod(2)

if x_mod > 0 || y_mod > 0
  puts "No"
  exit
end

if x_must_deduced > 0
  options = [0]
  until x_moves.empty?
    next_x = x_moves.shift
    break if next_x > x_must_deduced
    options += options.map{ |n| n + next_x }
    options.uniq!
    if options.include?(x_must_deduced)
      x_must_deduced = 0
      break
    end
  end
end

if y_must_deduced > 0
  options = [0]
  until y_moves.empty?
    next_y = y_moves.shift
    break if next_y > y_must_deduced
    options += options.map{ |n| n + next_y }
    options.uniq!
    if options.include?(y_must_deduced)
      y_must_deduced = 0
      break
    end
  end
end

if x_must_deduced == 0 && y_must_deduced == 0
  puts "Yes"
else
  puts "No"
end


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

int main(){
  long long  a,b,c,d,res;
  cin >> a >> b >> c >> d;
  res = a*c;
  res = max(res,a*d);
  res = max(res,b*c);
  res = max(res,b*d);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3636
import copy
def a():return input()#s
def ai():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y

N, M = ma()
PY = [lma() + [i] for i in range(M)]
KY = PY.sort()
ans = []
cnt = [0]*N
for p, y, i in PY: #for p, y, i in enumerate(PY): はできない
    ans.append(["%06d%06d" % (p, cnt[p - 1] + 1), i])
    cnt[p - 1] += 1
ans = sorted(ans, key=lambda x: x[1])
for a,i in ans:
    print(a)

Measured memory_bytes: 43688
#include <bits/stdc++.h>
#define boost() ios_base :: sync_with_stdio(0); cin.tie(); cout.tie(); cout << fixed; cout << setprecision(15); srand(time(NULL))
#define int long long
using namespace std;

const int N = 60;

signed main () {
  boost();
  int n; cin >> n;
  int mn = INT_MAX;
  int res = 0;
  for (int i = 0; i < n; i++) {
    int x; cin >> x;
    mn = min (mn, x);
    if (x <= mn) res++;
  }
  cout << res << endl;
}


Measured memory_bytes: 256