akhauriyash/Code-Regression huggingface dataset:
<?php
$s['a'] = str_split(trim(fgets(STDIN)));
$s['b'] = str_split(trim(fgets(STDIN)));
$s['c'] = str_split(trim(fgets(STDIN)));

$term = 'a';
for($i=0;$i<300;$i++){
  if(count($s[$term])==0){
    switch($term) {
      case 'a':
        echo "A";
        break;
      case 'b':
        echo "B";
        break;
      case 'c':
        echo "C";
        break;
    exit;
    }
  }
  $term = array_shift($s[$term]);
}

Measured memory_bytes: 4728
#include <stdio.h>

int main(){
  int N;
  scanf("%d",&N);
  int a;
  int S=0;
  for(int i=1;i<=N;i++){
    scanf("%d",&a);
    if(a==S+1) S++;
  }
  if(S==0) printf("-1\n");
  else printf("%d\n",N-S);
  return 0;
}

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

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
#define debug(fmt, ...) \
        fprintf( stderr, \
                  fmt "\n", \
                  ##__VA_ARGS__ \
        )

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int MOD = 1000000007;

// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

struct prepare {
    prepare() {
        cout.setf(ios::fixed, ios::floatfield);
        cout.precision(8);
        ios_base::sync_with_stdio(false);
    }
} _prepare;

int main() {
    int N, C;
    cin >> N >> C;
    vi A(N), B(N);
    rep(i, N)cin >> A[i];
    rep(i, N)cin >> B[i];

    // j^i
    vvll acc(401, vll(401, 0));
    rep(i, 401) {
        rep(j, 401) {
            if(j > 0)
                acc[i][j] = acc[i][j-1];
            acc[i][j] += fpow(j, i, MOD);
            acc[i][j] %= MOD;
        }
    }

    cerr << acc[3][4] << endl;

    vvll dp(N+1, vll(C+1, 0));
    dp[0][0] = 1;
    rep(i, N) {
        rep(c, C+1) {
            rep(j, c+1) {
                if(c-j < 0)
                    continue;
                ll v = (acc[j][B[i]] - acc[j][A[i]-1] + MOD) % MOD;
                ll t = dp[i][c-j] * v;
                t %= MOD;
                dp[i+1][c] += t;
                dp[i+1][c] %= MOD;
            }
        }
    }

    cout << dp[N][C] << endl;


    return 0;
}

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

int main(){
	int n, total, temp, min=10005;
	cin >> n >> total;
	for(int i=0;i<n;i++){
		cin >> temp;
		total-=temp;
		min=(temp<min?temp:min);
	}
	n+=total/min;
	cout << n << endl;
}

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

int main(){
    ll H;
    int N;
    cin >> H >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) H -= A[i];
    if (H <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    string s,t; cin>>s>>t;
    bool can=false;
    rep(i,s.size()){
        if(s==t){
            can=true;
            break;
        }
        s = s.back()+s.substr(0,s.size()-1);
    }
    cout<<(can?"Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 3516
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
#define N 100
typedef long long ll;
typedef pair<int,int>P;
typedef struct D
{
	int t,n,e;
	bool operator <(const D &a)const
	{
		if(t==a.t)return n>a.n;
		return t>a.t;
	}
}D;
priority_queue<D>F;
int r[N],s[20],w=0;

int ch(int n)
{
	for(int i=0;i<17;i++)
		if(s[i]==-1)
		{
			int j;
			for(j=0;j<n&&i+j<17;j++)if(s[i+j]!=-1)break;
			if(j==n)return i;
		}
	return -1;
}

void dbg(D t)
{
	printf("%3d    ",t.t);
	for(int i=0;i<17;i++)
		printf("%2d ",s[i]);
	printf("   %d",t.n);
	puts("");
}

int main()
{
	memset(s,-1,sizeof(s));
	for(int i=0;i<N;i++)
	{
		D tmp={i*5,i,0};
		F.push(tmp);
	}
	while(!F.empty())
	{
		D n=F.top();F.pop();

		if(n.e)
		{
			for(int i=0;i<17;i++)
				if(s[i]==n.n)s[i]=-1;
		}
		else
		{
			if(w<n.n)
			{
				n.t++;
				F.push(n);
				continue;
			}
			int a=n.n%5==1?5:2,b=ch(a);
			if(b!=-1)
			{
				for(int j=0;j<a;j++)
					s[b+j]=n.n;
				r[n.n]=n.t-5*n.n;
				w=n.n+1;
				D tmp={n.t+19+17*(n.n%2)+3*(n.n%3),n.n,1};
				F.push(tmp);
			}
			else
			{
				n.t++;
				F.push(n);
			}
		}
		//dbg(n);
	}
	for(;~scanf("%d",&w);)printf("%d\n",r[w]);
	return 0;
}

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

int count;

int gcd(int m,int n)
{
	if(m < n){
		int t = m;
		m = n;
		n = t;
	}
	if(n == 0)
		return m;
	count++;
	int tmp = m%n;
	return gcd(n,tmp);
}

int main()
{
	int m,n;
	while(cin >> m >> n){
		count = 0;
		if(m==0 && n==0)
			break;
		cout << gcd(m,n);
		cout << " " << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>
#include<cmath>

typedef long long ll;

#define debug(x) cout << #x << '=' << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << ' '
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>

using namespace std;

struct UnionFind{
    vector<int> parent;

    UnionFind(int N): parent(N,-1){
    }

    int root(int x){
        if(parent[x] < 0) return x;
        else {
            parent[x] = root(parent[x]);
            return parent[x];
        }
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;

        parent[rx] += parent[ry];
        parent[ry] = rx;

        return;
    }

    int size(int x){
        return -1 * parent[root(x)];
    }

    bool same(int x,int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    } 
};

int main(){
    int n,m;
    cin >> n >> m;

    vector<int> a(m),b(m);
    loop(i,m) cin >> a[i] >> b[i];

    UnionFind tree(n);

    vector<ll> result(m);

    result[m-1] = ll(n) * ll((n-1)) /2;
    loop(i,m-1){
        int tmpA = a[m-1-i] - 1;
        int tmpB = b[m-1-i] - 1;

        if(tree.same(tmpA,tmpB)){
            result[m-2-i] = result[m-1-i];
        }else{
            ll asize = tree.size(tmpA);
            ll bsize = tree.size(tmpB);

            result[m-2-i] = result[m-1-i] - (asize * bsize);
            tree.unite(tmpA,tmpB);
        }
    }

    loop(i,m){
        cout << result[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3328
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String S = sc.next();

		if (S.length() <= 1) {
			System.out.println("No");
		}
		else {
			String left = S.substring(0, N / 2);
			String right = S.substring((N / 2));
			if (left != null && left.equals(right)) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
		}
	}
}


Measured memory_bytes: 21844
data = input().split()  
n = int(data[0])
m = int(data[1])
x = [int(s) for s in input().split()]

x.sort()

y=[]
tmp=0
for i in x:
    y.append(i-tmp)
    tmp=i
y.pop(0)

y.sort()
y.reverse()

res=x[-1]-x[0]

if(len(y)+1 < n):
    n = len(y)+1

for i in range(n-1):
    res-=y[i]

print(res)

Measured memory_bytes: 13840
#include <bits/stdc++.h>
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
template <class T1, class T2>void print(T1 a[], T2 n) { for (T2 i = 0; i < n; i++) { cout << a[i] << " ";} cout << endl;}
template <class T1, class T2>void print(vector<T1> a, T2 n) { for (T2 i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl;}
ll modexpo(ll a, ll b, ll m) {if (b == 0) {return 1;} else if (a == 1) {return 1;} if (b % 2 == 0) {ll t = modexpo(a, b / 2, m); t = (t * t) % m; return t;} else {ll t = modexpo(a, b / 2, m); t = (t * t) % m; t = (t * a) % m; return t;}}

int dp[100005];
int visited[100005];



void dfs(int x, vector<int> g[]) {
	// if(dp[x]!=-1){
	// 	return dp[x];
	// }

	visited[x] = 1;
	int mm = 0;

	for (int i = 0; i < g[x].size(); i++) {
		int t = g[x][i];
		if (visited[t] == 0) {
			dfs(t, g);
		}
		mm = max(mm, dp[t] + 1) ;
	}
	dp[x] = mm;
}

int main() {

	// taskkill /IM "cp.exe" /F
	fast
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
//#endif



	int n, m;
	cin >> n >> m;
	vector<int> g[n + 1];
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		g[x].push_back(y);
	}
	memset(dp, -1, sizeof(dp));
	for (int i = 1; i <= n; i++) {
		dfs(i, g);
		// print(dp + 1, n);
	}

	int ans = 0;

	for (int i = 1; i <= n; i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;

}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main(void) {
    u64 N;
    cin >> N;

    u64 cnt = 0;
    u64 ans = false;

    for(u64 i=0; i<N; i++) {
        u64 d0, d1;
        cin >> d0 >> d1;
        
        cnt = (d0 == d1) ? cnt + 1 : 0;
        ans |= (cnt >= 3);
    }

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

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);

  int ans=(N-1+(K-2))/(K-1);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
using System;
using System.Linq;

namespace ITP1_7_B
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] nums = Console.ReadLine().Split(' ')
                    .Select(s => int.Parse(s))
                    .ToArray();
                if (nums.All(n => n == 0))
                    break;
                Console.WriteLine(CountCombi(nums[0], nums[1]));
            }
        }

        static int CountCombi(int n,int x)
        {
            int ret = 0;
            for(int i = 1; i < n - 1; i++)
            {
                for(int j = i + 1; j < n; j++)
                {
                    int temp = x - (i + j);
                    if (j < temp && temp <= n)
                        ret++;
                }
            }
            return ret;
        }
    }
}

Measured memory_bytes: 9580
//E869120さんのコード
#include <bits/stdc++.h>
using namespace std;
 
long long N; string S;
 
int main() {
	cin >> N;
	if (N == 0) { cout << "0" << endl; return 0; }
	while (N != 0) {
		if (N % 2 == 1 || N % 2 == -1) { N--; S += "1"; }
		else { S += "0"; }
		N /= -2;
	}
	reverse(S.begin(), S.end());
	cout << S << endl;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, a[108];

int main(){
	cin >> n;
	for(ll i = 1; i <= n; i++){cin >> a[i];}
	
	ll ans = 200*200*100;
	for(ll j = -100; j <= 100; j++){
		ll sum = 0;
		for(ll i = 1; i <= n; i++){
			sum += (a[i]-j)*(a[i]-j);
		}
		
		ans = min(sum, ans);
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    long long j,k,x,y,p,q;
    long long l;
    l=(c/__gcd(c,d))*d;
    j=(a-1)/c;
    k=(a-1)/d;
    p=j+k-((a-1)/l);
    x=b/c;
    y=b/d;
    q=x+y-b/l;
    p=(b-a)+(p-q);
    cout<<p+1<<endl;
}

Measured memory_bytes: 384
#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 bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
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;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 30;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll x; cin >> x;
    ll res = x / 11 * 2;
    if(x % 11){
        if(x % 11 <= 6){
            res++;
        }
        else {
            res += 2;
        }
    }
    cout << res << endl;

    return 0;
}


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

int main()
{
	int N;
	cin >> N;
	for (int i = N; i <= 999; i++)
	{
		int a = i / 100;
		int b = (i - a * 100) / 10;
		int c = i % 10;
		if (a==b&&b==c)
		{
			cout << i << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

int main(){
  int n; cin >> n;
  vector<int> d;
  for(int i=0;i<n;i++){
    int x; cin >> x;
    d.push_back(x);
  }
  int m; cin >> m;
  vector<int> t;
  for(int i=0;i<m;i++){
    int x; cin >> x;
    t.push_back(x);
  }
  sort(d.begin(), d.end());
  sort(t.begin(), t.end());
  int t_id=0, d_id=0;
  bool label=true;
  if(n<m) cout << "NO" << endl;
  else{
    while(t_id<m){
      if(t[t_id] == d[d_id]){
        t_id++;
        d_id++;
      }else if(t[t_id] < d[d_id]){
        label=false;
        break;
      }else{
        d_id++;
      }
    }
    if(label) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 2548
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;


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

  char work = s[0];
  int ans = 1;
  rep(i,n-1){
	if(work != s[i+1]){
	  work = s[i+1];
	  ans++;
	}
  }

  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 512
n,k = [int(x) for x in input().split()]
h = []
for _ in range(n):
    h.append(int(input()))

h_sorted = sorted(h)

ans = 10**10
for i in range(n-k+1):
    tmp = h_sorted[i+k-1] - h_sorted[i]
    ans = min(ans,tmp)

print(ans)

Measured memory_bytes: 8280
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int ar[100005];
int32_t main(){
	int n;cin>>n;
	for(int i=1;i<=n;i++){
		cin>>ar[i];
	}
	for(int i=1;i<=n-1;i++){
		if(ar[i]>ar[i+1] || (ar[i]>ar[i-1] && ar[i]==ar[i+1])){
			ar[i]--;
		}
	}
	if(is_sorted(ar+1,ar+n+1)){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define ll long long; int
using namespace std;


int main(void) {
   int a, b, k;
   cin >> a >> b >> k;
   for(int i = 100; i > 0; i--) {
       if(a % i == 0 && b % i == 0) {
           k--;
       }
       if(k == 0) {
           cout << i << endl;
           return 0;
       }
   }
}

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

int main() {
  int X[3], K, max=0, max_num;
  for(int i=0; i<3; i++) {
    cin >> X[i];
    if(max < X[i]) { max = X[i]; max_num=i; }
  }
  cin >> K;

  int sum=0;
  for(int j=0; j<K; j++) {
    X[max_num] *= 2;
  }
  for(int i=0; i<3; i++) {
    sum += X[i];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<climits>
#include<cstdlib>
#define ll long long
using namespace std;
int main() {
	ll sum=0,n;
	string s;
	cin >> s;
	n = stoi(s);//文字列から数値に変換
	for (ll i = 0; i < s.size(); i++) {
		sum += s[i]-'0';
	}
	if (n%sum == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){
	string s, t;
	cin >> s >> t;
	vector<int> cs(26, -1), ct(26, -1);
	bool f = true;
	for(int i = 0; i < s.size(); i++){
		int a = s[i] - 'a';
		int b = t[i] - 'a';
		if(cs[a] < 0){
			cs[a] = b;
		}else{
			if(cs[a] != b){
				f = false;
				break;
			}
		}
		if(ct[b] < 0){
			ct[b] = a;
		}else{
			if(ct[b] != a){
				f = false;
				break;
			}
		}
	}
	if(f){
		cout << "Yes" << endl;
	} else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}
int main(){
    int n,m;cin >> n >> m;
    vector<int> nv(n,2);
    int ans = 0;
    vector<int> mv(m,1);
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            ans++;
        }
    }
    for(int i=0;i<m-1;i++){
        for(int j=i+1;j<m;j++){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a[51],b[51],d,n,m,x,y,z,k,h,w,sum,mi,ma,ans,s,t,l[10],r,res,tmp,itr,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<int, int> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<int,int> > VP;

ll f[101][11],p[101][11],c[101];

int main(){
    cin>>n;
    rep(i,n)rep(j,10)cin>>f[i][j];
    rep(i,n)rep(j,11)cin>>p[i][j];
    ma=-inf;
    rep(i,1,1<<10){
        rep(j,n)c[j]=0;
        rep(j,10){
            rep(k,n)if((i>>j & 1) & f[k][j])c[k]++;
        }
        sum=0;
        rep(j,n)sum+=p[j][c[j]];
        ma=max(sum,ma);
    }
    p(ma);
    return 0;
}


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

int main(){
  int64_t N,K;
  cin >> N >> K;
  if(K%2==0){
    int64_t x=0;
    int64_t y=0;
    for(int i=1;i<=N;i++){
      if(i%K==0){
        x++;
      }else if(i%K==K/2){
        y++;
      }
    }
    cout << x*x*x+y*y*y << endl;
  }else{
    int64_t x=0;
    for(int i=1;i<=N;i++){
      if(i%K==0){
        x++;
      }
    }
    cout << x*x*x << endl;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        for (int i = N; i < 1000; i++)
        {
            if (i % 111 == 0)
            {
                WriteLine(i);
                return;
            }
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
int a[100001][4],f[100001][4];
int main()
{
        int i,j,k,n;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
                scanf("%d %d %d",&a[i][1],&a[i][2],&a[i][3]);
        for(i=1;i<=n;i++)
        {
                for(j=1;j<=3;j++)
                {
                        for(k=1;k<=3;k++)
                        {
				if(k!=j)
                                	f[i][j]=max(f[i-1][k]+a[i][j],f[i][j]);
                        }
                }
        }
        printf("%d",max(f[n][1],max(f[n][2],f[n][3])));
        return 0;
}               

Measured memory_bytes: 3328
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		sc.close();
		out.println(a*b);
	}
}


Measured memory_bytes: 26996
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Stack;

public class Main {
    private static final Reader reader = new Reader();
    private static final int MAX = 100000;
    public static void main(String[] args) throws Exception{
        int n = reader.readInt();
        int[] nums = reader.readIntArray();
        int totXor = 0;
        for(int i=0;i<n;i++){
            totXor^=nums[i];
        }
        for(int i=0;i<n;i++){
            System.out.print((totXor^nums[i])+" ");
        }
    }


    private static class Reader{
        private final BufferedReader br;
        public Reader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public int readInt() throws Exception{
            return Integer.parseInt(br.readLine());
        }
        public long readLong() throws Exception {
            return Long.parseLong(br.readLine());
        }
        public double readDouble() throws Exception {
            return Double.parseDouble(br.readLine());
        }
        public String readLine() throws Exception{
            return br.readLine();
        }
        public int[] readIntArray() throws Exception{
            String[] tokens = br.readLine().split(" ");
            int[] nums = new int[tokens.length];
            for(int i=0;i<tokens.length;i++){
                nums[i] = Integer.parseInt(tokens[i]);
            }
            return nums;
        }
        public long[] readLongArray() throws Exception{
            String[] tokens = br.readLine().split(" ");
            long[] nums = new long[tokens.length];
            for(int i=0;i<tokens.length;i++){
                nums[i] = Long.parseLong(tokens[i]);
            }
            return nums;
        }
        public double[] readDoubleArray() throws Exception {
            String[] tokens = br.readLine().split(" ");
            double[] nums = new double[tokens.length];
            for(int i=0;i<tokens.length;i++){
                nums[i] = Double.parseDouble(tokens[i]);
            }
            return nums;
        }
        public String[] readWords() throws Exception {
            return br.readLine().split(" ");
        }
    }
}

Measured memory_bytes: 61300
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
if N % 2 == 0:
	print(0.5)
else:
	print(((N+1)*1/2)/N)

Measured memory_bytes: 3896
#include <iostream>
#include<bits/stdc++.h>
#define rep(k,i,n) for(int i=k;i<n;++i)
using namespace std;
int main(void){
    // Your code here!
    int N,K,h,ans=0;
    cin>>N>>K;
    rep(0,i,N){
        cin>>h;
        if(h>=K)++ans;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    string s;
    cin >> s;
    int r= 0,b= 0;
    rep(i,s.size()){
        s[i] == '1' ? r++ : b++;
    }
    cout << 2 * min(r, b) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    string a,b;
    cin >> a >> b;
    ll ans = 0;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] != b[i])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3916
n = int(input())
an = list(map(int,input().split()))
bn = list(map(int,input().split()))
nokori = 0
mon = 0
for i in range(n+1):
    if i != n:
        a = an[i]
        if a<=nokori:
            mon += a
            nokori = bn[i]
        else:
            mon += nokori
            a -= nokori
            if a <= bn[i]:
                mon += a
                nokori = bn[i]-a
            else:
                mon += bn[i]
                nokori = 0
    else:
        a = an[i]
        mon += min(a,nokori)

print(mon)
    


Measured memory_bytes: 19156
//package atcoder;
 
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int gugu = N*(N-1)/2;
		int kiki = M*(M-1)/2;
		System.out.println(gugu+kiki);
	}
}


Measured memory_bytes: 23508
eikaku = 0
tyokkaku = 0
donnkaku = 0
checker = True
while checker:
    tl = sorted(list(map(int, input().split()))) # tl= triangle_list
    if tl[0] + tl[1] - tl[2] > 0:
        criterion = tl[0]**2 + tl[1]**2 - tl[2]**2
        if criterion > 0:
            eikaku += 1
        elif criterion == 0:
            tyokkaku += 1
        else:
            donnkaku += 1
    else:
        print(eikaku+tyokkaku+donnkaku, tyokkaku, eikaku, donnkaku)
        checker = False


Measured memory_bytes: 5600
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
typedef long long ll;

int main(){

	//int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
	int N, H, W, A, B, **ans, flag = 0, i, j, ans_0 = 0, ans_W = 0, len;

//	int count[1000000000] = { 0 };

	scanf("%d", &N);
	for (i = 0; i < N; i++){
		scanf("%d", &A);
		if (A % 2 == 0){
			if (A % 5 == 0 || A % 3 == 0){
				continue;
			}
			else{
				printf("DENIED\n");
				return 0;
			}
		}
	}

	printf("APPROVED\n");

	/*
	ans = (int **)malloc(sizeof(int *)* H);


	for (i = 0; i<H; i++) {
		ans[i] = (int *)malloc(sizeof(int)* W);
	}

	for (i = 0; i < H; i++){
		for (j = 0; j < W; j++){
			ans[i][j] = 0;
		}
	}
	*/

	return 0;

}
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr i64 mod = 1000000007;
    int n;
    std::cin >> n;
    std::vector<int> lb(n), a(n), t(n), q(n);
    for (auto &e : t) std::cin >> e;
    for (auto &e : a) std::cin >> e;

    int h = 0;
    for (int i = 0; i < n; i++) {
        if (h != t[i]) q[i] = h = t[i];
        lb[i] = h;
    }

    h = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (h != a[i]) {
            if (q[i] && q[i] != a[i]) {
                std::cout << 0 << std::endl;
                return 0;
            }
            if (!q[i]) q[i] = a[i];
            h = a[i];
        }
        if (q[i] && q[i] > h) {
            std::cout << 0 << std::endl;
            return 0;
        }
        lb[i] = std::min(lb[i], h);
    }

    i64 ret = 1;
    for (int i = 0; i < n; i++) {
        if (q[i]) continue;
        ret = ret * lb[i] % mod;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 1792
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace abc151
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_abc151A();
        }

        public static void solve_abc151B()
        {

        }

        public static void solve_abc151A()
        {
            Console.WriteLine(Convert.ToChar(Convert.ToChar(Console.ReadLine()) + 1));
        }
    }
}


Measured memory_bytes: 11220
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;
 
 
 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
    int n = sc.nextInt();
    int m = sc.nextInt();

    int ansmax = m / n;

    for(int ans = m / n; ans > 0; ans--){
      if((m % (ans * n)) % ans == 0){
        System.out.println(ans);
        break;
      }
    }


  }
 
 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;
 
      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }
 
      public char nextChar() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        char ret;
        do{
          ret = (char)c;
          c = next();
        }while(!isSpaceChar(c));
        return ret;
      }
 
      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

Measured memory_bytes: 22612
#include "bits/stdc++.h"
using namespace std;

//諸機能
#pragma region MACRO 
#define putans(x)  cerr << "answer: " ; cout << (x) << endl
#define dputans(x) cerr << "answer: "; cout << setprecision(10) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define substr(s,i,l) string((s), (i), (l))
#define tos(x) (to_string((x)))
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define input ifs >>
#else //いい感じにやる
#define input cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#ifndef _DEBUG
#define dbg1 {}
#define dbg2 {}
#define dbg3 {}
#define dbgArray {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e9)
#pragma endregion

int main() {
	ll x[3];
	input x[0]>> x[1]>> x[2];
	ll ans = x[0]*x[1]*x[2];
	rep(i, 3) {
		if (x[i] % 2 == 0) {
			putans(0);
			return 0;
		}
	}
	rep(i, 3) {
		ll a = ( x[i % 3] / 2 ) * x[( i + 1 ) % 3] * x[( i + 2 ) % 3];
		ll b = ( x[i % 3] - x[i % 3] / 2 ) * x[( i + 1 ) % 3] * x[( i + 2 ) % 3];
		ans = min(ans, abs(b - a));
	}
	putans(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n;
  string s;
  cin >> n >> s;
  ll k=s.size();
  vl cnt(26);
  rep(i,k){
    rep(j,26){
      if(abc[j]==s[i]){
        cnt[j]++;
      }
    }
  }
  ll ans=1;
  rep(i,26){
    ans =ans*(1+cnt[i])%MOD;
  }
  cout << ans-1 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort(all(v))
#define INF 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );};



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

  int n, k;
  cin >> n >> k;
  ll h[100010];
  rep(i, n) cin >> h[i];
  ll dp[100100];
  fill(dp, dp + 100100, INF);
  dp[0] = 0;
  rep(i, n) {
    REP(j, 1, k + 1) {
      dp[i + j] = min(dp[i + j], (dp[i] + abs(h[i] - h[i + j])));
    }
  }
  
  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;




int main(int,  char **)
{
#ifdef LOCAL
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    long long a, b, c, k;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
    long long ans = a - b;
    if (k % 2 == 1)
        ans = -ans;
    printf("%lld\n", ans);


	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
	unsigned short *A, *B;
	int C[VMAX+1];
	int n, i, j;
	
	scanf("%d", &n);
	
	A = malloc(sizeof(short)*n+1);
	B = malloc(sizeof(short)*n+1);
	
	/* your code */

	for(i=0; i<=VMAX; i++){
		C[i] = 0;
	}
	
	for(i=0; i<n; i++){
		scanf("%hu", &A[i+1]);
		C[A[i+1]]++;
	}
	
	for(i=1; i<=VMAX; i++){
		C[i] = C[i] + C[i-1];
	}
	
	for(j=1; j<=n; j++){
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
	
	for(i=1; i<=n; i++){
		if(i>1){ printf(" "); }
		printf("%d", B[i]);
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 9584
#include<stdio.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
#define swap(a,b) ((*a!=*b)&&(*a+=*b,*b=*a-*b,*a-=*b))
const int IMIN=(1<<31);
static inline long IN(void)
{
  long x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void Sort(unsigned *from,unsigned *to,unsigned bit)
{
  if(!bit||to<from+1)return;
  unsigned *left=from,*right=to-1;
  for(;;)
  {
    while(left<right&&!(*left&bit))left++;
    while(left<right&&(*right&bit))right--;
    if(left>=right)break;
    swap(left,right);
  }
  if(!(bit&*left)&&left<to)left++;
  bit>>=1;
  Sort(from,left,bit);
  Sort(left,to,bit);
}
static inline void Radix(int *array,const int len)
{
  unsigned *x=(unsigned*)array;
  rep(i,len)x[i]^=IMIN;
  Sort(x,x+len,IMIN);
  rep(i,len)x[i]^=IMIN;
}
int main(void)
{
  int N=IN(),x,p=0,m=0,z=0,sign=0,A[200000];
  long K=IN(),count=0,l=-2e18,r=-l,mid;
  while(N--){x=IN();if(x>0)A[m+p++]=x;else if(x<0)A[p+m++]=x;else z++;}
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;
  Radix(A,m+p);rep(i,m)A[i]*=-1;
  if(K<=1l*m*p)r=1l;else l=-1l;
  while(l<=r)
  {
    mid=(l+r)/2;count=0;
    if(mid>=0)
    {
      int plus=p-1,minus=m-1;count+=1l*z*(p+m)+1l*z*(z-1)/2+1l*p*m;
      rep(i,plus){while(1l*A[m+i]*A[m+plus]>mid){plus--;}if(i>=plus){break;}count+=1l*plus-i;}
      rep(i,minus){while(1l*A[m-1-i]*A[m-1-minus]>mid){minus--;}if(i>=minus){break;}count+=1l*minus-i;}
    }
    else{mid*=-1l;sign=1;int low=0;rep(i,m){while(1l*A[m+low]*A[i]<mid&&low<p){low++;}count+=1l*p-low;}}
    if(count>=K){if(sign)r=-mid-1l;else r=mid-1l;}else{if(sign)l=-mid+1l;else l=mid+1l;}
  }
  return OUT(l),0;
}

Measured memory_bytes: 2172
#include<bits/stdc++.h>
#define maxn 300005
#define LL long long
#define inf 0x3f3f3f3f3f3f3f3fll
using namespace std;

int n;
LL s[maxn],t[maxn],f[maxn],g[maxn],F[maxn],G[maxn],h[maxn];

void dp(LL *f){
	static LL q[maxn],qr=0,y[maxn]={};
	q[qr=1] = 0;
	for(int i=1;i<=n;i++){
		for(;qr>1 && y[q[qr]] - y[q[qr-1]] <= i * (q[qr] - q[qr-1]);qr--);
		f[i] = max(f[q[qr]] + (i - q[qr]) * (i - q[qr] + 1ll) / 2 - s[i] + s[q[qr]] , f[i-1]); 
		y[i] = f[i] + s[i] + i * (i-1ll) / 2;
		for(;qr>1 && (i-q[qr]) * (y[q[qr]]-y[q[qr-1]]) <= (y[i]-y[q[qr]]) * (q[qr] - q[qr-1]);qr--);
		q[++qr] = i;
	}
}

void Sol(int l,int r){
	if(l==r) return ;
	int m=l+r>>1;
	Sol(l,m),Sol(m+1,r);
	for(int i=l;i<=m;i++) F[i] = f[i] + s[i] + i * (i + 1ll) / 2;
	static LL q[maxn],qr,t[maxn];
	qr=0;
	for(int i=m+1;i<=r;i++){
		G[i] = g[i] - s[i-1] + i * (i - 1ll) / 2;
		for(;qr>1 && (i - q[qr]) * (G[q[qr]] - G[q[qr-1]]) <= (G[i] - G[q[qr]]) * (q[qr] - q[qr-1]);qr--);
		q[++qr] = i;
	}
	for(int i=l;i<=m;i++){
		for(;qr > 1 && (G[q[qr]] - G[q[qr-1]]) <= i * (q[qr] - q[qr-1]);qr--);
		if(qr) t[i] = F[i] + G[q[qr]] - i * q[qr];
		else t[i] = -inf;
		if(i>l) t[i] = max(t[i] , t[i-1]);
		if(i>l) h[i] = max(h[i] , t[i-1]);
	}
}

int main(){	
//freopen("1.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&t[i]),s[i]=s[i-1]+t[i];
	dp(f);
	for(int i=1;i<n-i+1;i++) swap(t[i],t[n-i+1]);
	for(int i=1;i<=n+1;i++) s[i] = s[i-1] + t[i];
	dp(g);	
	for(int i=1;i<n-i+1;i++) swap(t[i],t[n-i+1]);	
	for(int i=1;i<n-i+1;i++) swap(g[i],g[n-i+1]);
	for(int i=1;i<=n+1;i++) s[i] = s[i-1] + t[i];
	
	memset(h,-0x3f,sizeof h);
	Sol(0,n+1);
	for(int i=1;i<n-i+1;i++) swap(t[i],t[n-i+1]);
	for(int i=1;i<n-i+1;i++) swap(f[i],f[n-i+1]);
	for(int i=1;i<n-i+1;i++) swap(g[i],g[n-i+1]);
	swap(f,g);
	for(int i=1;i<=n+1;i++) s[i] = s[i-1] + t[i];
	for(int i=1;i<n-i+1;i++) swap(h[i],h[n-i+1]);
	Sol(0,n+1);
	for(int i=1;i<n-i+1;i++) swap(t[i],t[n-i+1]);
	for(int i=1;i<n-i+1;i++) swap(h[i],h[n-i+1]);
	for(int i=1;i<n-i+1;i++) swap(f[i],f[n-i+1]);
	for(int i=1;i<n-i+1;i++) swap(g[i],g[n-i+1]);
	swap(f,g);
	int Q;scanf("%d",&Q);
	for(LL x,y;Q--;){
		scanf("%lld%lld",&x,&y);
		printf("%lld\n",max(h[x]+t[x]-y,f[x-1]+g[x+1]));
	}
}

Measured memory_bytes: 27136