akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 1000000007
const int N = 200010 , LOG = 19;
int n , arr[N] , k , nxt[N];

int st[LOG][N] , st2[LOG][N] , lg[N];

vector< int > v;
long long ans = 0;

void build(){
    lg[1] = 0;
    for(int i = 2;i < N;i++){
        lg[i] = lg[i - 1];
        if((1 << (lg[i] + 1)) == i){
            lg[i]++;
        }
    }
    for(int k = 1;k < LOG;k++){
        for(int i = 0 ; i + (1 << k) - 1 < n;i++){
            st[k][i] = min(st[k - 1][i] , st[k - 1][i + (1 << (k - 1))]);
            st2[k][i] = max(st2[k - 1][i] , st2[k - 1][i + (1 << (k - 1))]);
        }
    }
}

int L;

inline int get_max(int l,int r){
    L = lg[r - l + 1];
    return max(st2[L][l] , st2[L][r - (1 << L) + 1]);
}

inline int get_min(int l,int r){
    L = lg[r - l + 1];
    return min(st[L][l] , st[L][r - (1 << L) + 1]);
}

bool is_less_than(int i,int j){
    if(i > j){
        if(j + k - 1 < i){
            if(nxt[j] < j + k - 1)
                return false;
            if(nxt[i] < i + k - 1)
                return true;
            return false;
        }
        if(get_max(j , i - 1) > get_min(i , j + k - 1))
            return false;
        if(nxt[j] < i - 1)
            return false;
        if(get_max(i , j + k - 1) > get_min(j + k , i + k - 1))
            return true;
        if(nxt[j + k] < i + k - 1)
            return true;
        return false;
    }
    if(i + k - 1 < j){
        if(nxt[i] < i + k - 1)
            return true;
        return false;
    }
    if(get_max(i , j - 1) > get_min(j , i + k - 1))
        return true;
    if(nxt[i] < j - 1)
        return true;
    return false;
}

int main(){
    scanf("%d%d",&n,&k);
    for(int i = 0 ;i < n;i++){
        scanf("%d",&arr[i]);
        if(i + k - 1 < n) v.push_back(i);
        st[0][i] = st2[0][i] = arr[i];
    }

    for(int i = n - 1;i >= 0;i--){
        if(i == n - 1 || arr[i] > arr[i + 1])
            nxt[i] = i;
        else
            nxt[i] = nxt[i + 1];
    }
    build();
    sort(v.begin(),v.end(),is_less_than);
    int ans = (int)v.size();
    for(int i = 1;i < (int)v.size();i++){
        if(!is_less_than(v[i - 1] , v[i])){
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 33140
import sys
N, Y = map(int, input().split())
 
for x in range(N+1)[::-1]:
  if x <= N:
    for y in range(N-x+1)[::-1]:
      if x+y <= N:
        z = N-(x+y)
        if 10000*x + 5000*y + 1000*z == Y:
          print(x,y,z)
          sys.exit()
 
print(-1,-1,-1)

Measured memory_bytes: 3188
import math

N = int(input())

ans = 0
counter = [[0]*10 for i in range(10)]
for i in range(1,N+1):
    str_i = str(i)
    counter[int(str_i[0])][int(str_i[-1])] += 1

for i in range(1,10):
    for j in range(1,10):
        ans += counter[i][j] * counter[j][i]

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>

using namespace std;

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

ll a[60];

int main(){
    int N;  cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    ll l = 0, r = LONG_LONG_MAX;
    while(r - l > 1){
        ll m = (l + r) / 2;
        ll x = 0;
        for(int i = 0; i < N; i++){
            x += (a[i] + m + 1) / (N + 1);
        }
        if(x < m){
            r = m;
        }
        else{
            l = m;
        }
    }

    ll res = 0;
    for(ll x = max(0LL, l-N*N); x <= l; x++){
        ll y = 0;
        for(int i = 0; i < N; i++){
            y += (a[i] + x + 1) / (N + 1);
        }
        if(y <= x){
            res = x;
            break;
        }
    }

    cout << res << endl;


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  int n;cin >> n;
  queue<ll> q;
  rep1(i,9) q.push(i);

  ll res;
  rep(i,n) {
    res = q.front(); q.pop();
    ll x = res % 10;
    if(x == 0) {
      q.push( res*10 + x );
      q.push( res*10 + x + 1);            
    }
    else if(x == 9) {
      q.push( res*10 + x - 1);
      q.push( res*10 + x );
    }
    else {
      q.push( res*10 + x - 1);
      q.push( res*10 + x );
      q.push( res*10 + x + 1);      
    }
  }

  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int main()
{
	#define int long long
	int n,m;
	cin >> n >> m;
	int l[m],r[m];
	for(int i = 0; i < m; i++)
	cin >> l[i] >> r[i];
	int up = r[0],low = l[0];
	int flag = 0,ans = 0;
	for(int i = 1; i < m; i++)
	{
		if(l[i] > up || r[i] < low)
		{
			flag = 1;
			break;
		}
		else if(l[i] > low)
		{
			low = l[i];
		}
		if(r[i] < up)
		{
			up = r[i];
		}
	}
	if(flag)
	{
		cout << ans << "\n";
	}
	else
	{
		ans = up-low+1;
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s; cin>>s; int x=0;
  for(int i=0;i<s.size()/2;i++){
    if(s.at(i)!=s.at(s.size()-i-1)) x++;
  }
  cout<<x<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    
    int[] l = new int[n];
    int bound = 0;
    int count = 1;
    
    for(int i =0; i < n; i++){
      bound += sc.nextInt();
      
      if(bound > x){
        break;
     }   
      count++;
    }
    System.out.println(count);
  }
 }

Measured memory_bytes: 23124
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    vector<int> b(n);
    REP(i,n) cin >> b[i];
    int k=0,l=0;
    rep(i,n){
        if(a[i]>b[i]){
            k+=max(0LL,a[i]-b[i]);
        }
        else{
            l+=max(0LL,(b[i]-a[i])/2);
        }
    }
    if(k<=l)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


}

Measured memory_bytes: 384
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc  = new Scanner(System.in);
    int k = sc.nextInt();
    int s = sc.nextInt();
    int sum = 0;
    for(int i = 0; i <= k; i++){
      for(int j = 0;j <= k; j++){
        if(s - i - j <= k && s - j - i >= 0){
          sum++;
        }
      }
    }
    System.out.println(sum);
  }
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

string s;

pair<int,string> solve(int idx){
  string ans="";
  bool ok=true;
  int c=0;
  pair<int,string> ret;
  for(;idx<s.length();idx++){
    if(s[idx]=='['){
      if(!ok) return {-1,"{"};
      ret=solve(idx+1);
      if(ret.second=="{") return {-1,"{"};
      reverse(ret.second.begin(),ret.second.end());
      ans+=ret.second;
      idx=ret.first;
    }else if(s[idx]==']'){
      if(ok) return {idx,ans};
      else return {-1,"{"};
    }else if(s[idx]=='+'){
      ok=false;
      c=(c+1)%26;
    }else if(s[idx]=='-'){
      ok=false;
      c=(c+25)%26;
    }else{
      if(s[idx]=='?'){
        ans+=string(1,'?');
      }else{
        ans+=string(1,'A'+((s[idx]-'A')+c)%26);
      }
      ok=true;
      c=0;
    }
  }
  return {s.length(),ans};
}

int main(){
  while(1){
    cin >> s;
    if(s==".") return 0;
    pair<int,string> ret;
    ret=solve(0);
    for(int i=0;i<ret.second.length();i++) if(ret.second[i]=='?') ret.second[i]='A';
    cout << ret.second << endl;
  }
  return 0;
}



Measured memory_bytes: 3208
#include<cstdio>
const int N=1e5+5;
int q,A[N],B[N],l,r,L,R;char s[N];
int main(){
	scanf("%s",s+1);for(int i=1;s[i];++i)A[i]=A[i-1]+s[i]-64;
	scanf("%s",s+1);for(int i=1;s[i];++i)B[i]=B[i-1]+s[i]-64;
	for(scanf("%d",&q);q--;)scanf("%d%d%d%d",&l,&r,&L,&R),puts((A[r]-A[l-1])%3==(B[R]-B[L-1])%3?"YES":"NO");
	return 0;
}

Measured memory_bytes: 1408
N = int(input())
S = input()

E = [0]*(N+1)
W = [0]*(N+1)

for i in range(N):
    if S[i] == "E":
        E[i+1] = E[i] + 1
        W[i+1] = W[i]
    else:
        E[i+1] = E[i]
        W[i+1] = W[i] + 1

min = N

for i in range(N):
    S = W[i]-W[0] + E[N]-E[i+1]
    if S < min:
        min = S
    
print(min)

Measured memory_bytes: 23484
#include <bits/stdc++.h>
#define rep(i,s,n) for (ll i = s; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using graph = map<ll,vector<ll>>;

int main() {
  ll n;
  cin >> n;
  graph G;
  rep(i,0,n-1) {
    ll u,v;
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  vector<ll> e(n+1,0);
  rep(v,1,n+1) {
    ll a = 0;
    for (auto nv : G[v]) {
      if (nv < v) a++;
    }
    e[v] = e[v-1] + a;
  }
  ll s = 0;
  rep(i,1,n+1) s += e[i];
  ll ans = 0;
  rep(i,1,n+1) {
    ll k = (n+1-i) * (n+2-i) / 2;
    ans += k - s;
    for (auto nv : G[i]) {
      if (nv > i) s -= n-nv+1;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


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

using i64 = long long int;

int imos[1003][1003]={0};

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;++i){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        imos[y1][x1]++;
        imos[y1][x2]--;
        imos[y2][x1]--;
        imos[y2][x2]++;
    }

    for(int i=0;i<=1000;++i){
        for(int j=0;j<=1000;++j){
            imos[i][j+1] += imos[i][j];
        }
    }

    for(int j=0;j<=1000;++j){
        for(int i=0;i<=1000;++i){
            imos[i+1][j] += imos[i][j];
        }
    }

    int ans = 0;
    for(int i=0;i<=1000;++i){
        for(int j=0;j<=1000;++j){
            ans = max(ans, imos[i][j]);
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 7020
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (100000)

using namespace std;

long solve_covered(long *num_bit_sets, long Kd, long k, long N) {
  long res = 0;
  for (long l = 0; l < 40; l++) {
    const long mask = 1L << l;
    if (l < k) {
      // set the bits freely
      res += max(num_bit_sets[l], N - num_bit_sets[l]) * mask;
    } else {
      if ((Kd & mask) == 0) {
        // only zero is allowed for this bit
        res += num_bit_sets[l] * mask;
      } else {
        // set bits freely
        res += max(num_bit_sets[l], N - num_bit_sets[l]) * mask;
      }
    }
    // printf("num_bit_set = %ld, num_bit_not_set = %ld, mask = %ld\n",
    //        num_bit_sets[l], N - num_bit_sets[l], mask);
  }
  // printf("k = %ld, Kd = %08x, res = %ld\n", k, Kd, res);
  return res;
}

int main(int argc, char *argv[]) {
  // read inputs
  long N, K, as[MAX_N];
  scanf("%ld %ld", &N, &K);
  for (long i = 0; i < N; i++) {
    scanf("%ld", &as[i]);
  }

  // obtain the solution witout thinking about "<= K"
  long num_bit_sets[40];
  long Xd = 0;
  for (long k = 0; k < 40; k++) {
    const long mask = 1L << k;
    long num_bit_set = 0;
    for (long i = 0; i < N; i++) {
      if (as[i] & mask) {
        num_bit_set++;
      }
    }
    num_bit_sets[k] = num_bit_set;
    if (N - num_bit_set > num_bit_set) {
      Xd |= mask;
    }
  }
  // for (long k = 0; k < 40; k++) {
  //   printf("k = %ld, num_bit_set = %ld\n", k, num_bit_sets[k]);
  // }

  // use "covered by Kd" instead of "<= K"
  long ans = solve_covered(num_bit_sets, K, 0, N);
  for (long k = 0; k < 40; k++) {
    const long mask = 1L << k;
    if (k == 0 || (K & mask) != 0) {  // kth LSB is set
      const long Kd = (K & ~mask) | (mask - 1);
      long val = solve_covered(num_bit_sets, Kd, k, N);
      ans = max(ans, val);
    }
  }
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 896
#include <stdio.h>
int main(void){
    int n,x,i,ii,iii,c=0;
    for(;;){
        c=0;
        scanf("%d %d",&n,&x);
        if(n==0 && x==0)break;
        for(i=1;i<=n-2;i++){
            for(ii=i+1;ii<=n-1;ii++){
                for(iii=ii+1;iii<=n;iii++){
                    if(iii+ii+i==x){
                        c++;
                        //printf("%d %d %d\n",i,ii,iii);
                    }
                }
                
            }
        }
        printf("%d\n",c);
    }
    
    return 0;
}


Measured memory_bytes: 1816
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x)     		(x).begin(),(x).end()
#define ub    			upper_bound
#define lb 				lower_bound
#define ins				insert
#define int 			long long
#define endl			'\n'
#define ff              first
#define ss              second
#define ull				unsigned long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define si 				set<int>
#define usi 			unordered_set<int>		
#define mii             map<int,int>
#define umii			unordered_map<int ,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,a,n)		for(int i=a;i<n;++i)
#define repd(i,a,n)		for(int i=a;i>n;--i)
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define deb(x)			cout<<#x <<"="<<x<<endl;
#define deb2(x,y)		cout<<#x<<"="<<x<<"  "<<#y<<"="<<y<<endl;
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int Pow(int a,int b){int res=1;while(b>0){if(b&1)res*=a;a*=a;b/=2;}return res;}
int MPow(int a,int  b){int res=1;while(b>0){if(b&1)res=(res*a)%Mod;a=(a*a)%Mod;b/=2;}return res%Mod;}
int log(int x){return 64-__builtin_clzll(x)-1;}

void c_p_p()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
}
struct Node
{
	int a,b,c,d;
	
};
bool cmp(Node A,Node B)
{
	return A.a<B.a;
}
const int Max=1e5+1;

int32_t main()
{
	c_p_p();
	int x,y;
	cin>>x>>y;
	if(2*x>y || 4*x<y)cout<<"No";
	else 
	{
		if(y&1)
			cout<<"No";
		else cout<<"Yes";
	}
	return 0;
}
	

Measured memory_bytes: 3672
a,b,c,d,e,f=gets.split.map(&:to_i)

puts 0.step(f,a*100).flat_map{|at|
  fa=f-at
  0.step(fa,b*100).flat_map{|bt|
    fb=fa-bt
    water=at+bt
    maxsugar=water/100*e
    0.step([fb,maxsugar].min,c).flat_map{|ct|
      fc=fb-ct
      0.step([fc,maxsugar-ct].min,d).flat_map{|dt|
        sugar=ct+dt
        water>0?[[sugar+water,sugar]]:[]
      }
    }
  }
}.max_by{|a,b|1.0*b/a}*" "

Measured memory_bytes: 56544
#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;
#define rep(i,a,n) for(int i = a;i < n;i++)
#define repr(i,a,n) for(int i = n-1;i >= a;i--)
#define sort(x) sort(ALL(x))
#define ALL(v) v.begin(), v.end()
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
}

void YNout(bool check){
	if(check)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return;
}

void Yayout(bool check){
	if(check) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	
	return;
}

/*
template <typename T>
void vecout(vector<T>& vecout_vec){
	
	rep(i,0,vecout_vec.size()){
		cout << vecout_vec.at(i) << endl;
	}
	
	return ;
}

template <typename T>
void vecin(vector<T>& vecin_vec, ll n){
	
	ll temp ;
	
	rep(i,0,n){
		cin >> temp;
		vecin_vec.push_back(temp);
		
	}
}

template <typename T>
void in(T& literal_in, T& literal_in2, ...){
	cin >> literal_in;
	in(literal_in2, ...);
	
	return;
}

template <typename T>
void in(T& literal_in){
	
	cin >> literal_in;
	
	return;
}

template <typename T>
void out(T& literal_out, T& literal_out2, ...){
	cout << literal_out << endl;
	out(literal_out2, ...);
	
	return;
}

template <typename T>
void out(T& literal_out){
	
	cout << literal_out << endl;
	
	return;
}
*/
signed main(){
	ll n;
	cin >> n;
	vector<pair<string,pair<ll,ll>>> vec;
	string s;
	ll t;
	pair<string,pair<ll,ll>> p;
	rep(i,0,n){
		cin >>s >> t;
		
		p.fs = s;
		p.sc.fs = t;
		p.sc.sc = i+1;
		vec.push_back(p);
	}
	
	sort(vec);
	
	
	ll memo = 0;
	rep(i,0,n-1){
		memo++;
		
		if(vec[i].fs != vec[i+1].fs){
			rep(j,0,memo){
				cout << vec[i-j].sc.sc << endl;
			}
			memo = 0;
		}
	}
	
	rep(i,0,memo+1){
		cout << vec[n-1-i].sc.sc << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> sum(n);
    vector<int> rsum(n);
    rep(i, n) {
        if (i==0) {
            sum[i] = (s[i]=='W');
            continue;
        }
        sum[i] = sum[i-1] + (s[i]=='W');
    }
    for (int i=n-1; i>=0; i--) {
        if (i==n-1) {
            rsum[i] = (s[i]=='E');
            continue;
        }
        rsum[i] = rsum[i+1] + (s[i]=='E');
    }
    int ans = n+5;
    rep(i, n) {
        int res = 0;
        if (i>0) res += sum[i-1];
        if (i<n-1) res += rsum[i+1];
        chmin(ans, res);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3076
#include <stdio.h>
#include <string.h>

int main(void)
{
 char a[11],b[11],c[11],d,e;

  scanf("%s%s%s",a,b,c);

  d=strlen(a);
  e=strlen(b);
 if((a[d-1]==b[0])&&(b[e-1]==c[0])){
    printf("YES\n");
  }
 else printf("NO\n");

 return 0;
}



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

int main() {
	int n;
	string line;
	cin>>n>>line;
	int sum=0;
	int max=0;
	for (int i=0; i<line.length(); i++){
		if (line[i]=='D'){
			sum-=1;
		}
		else if (line[i]=='I'){
			sum+=1;
			if (sum>max){
				max=sum;
			}
		}
	}
	cout << max << endl;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

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

// ただのセグメント木 (区間最大, long long)
struct SegmentTree {
private:
  int n;
  vector<ll> node;

public:
    // 元配列 v をセグメント木で表現する
  SegmentTree(vector<ll> v) {
    // 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
    // セグメント木全体で必要なノード数は 2n-1 個である
    int sz = v.size();
    n = 1; while(n < sz) n *= 2;
    node.resize(2*n-1, -1); // 最小値は-1

    // 最下段に値を入れたあとに、下の段から順番に値を入れる
    // 値を入れるには、自分の子の 2 値を参照すれば良い
    for(int i=0; i<sz; i++) node[i+n-1] = v[i];
    for(int i=n-2; i>=0; i--) node[i] = max(node[2*i+1], node[2*i+2]);
  }

  void update(int x, ll val) {
    // 最下段のノードにアクセスする
    x += (n - 1);

    // 最下段のノードを更新したら、あとは親に上って更新していく
    node[x] = val;
    while(x > 0) {
      x = (x - 1) / 2;
      node[x] = max(node[2*x+1], node[2*x+2]);
    }
  }

    // 要求区間 [a, b) 中の要素の最大値を答える
    // k := 自分がいるノードのインデックス
    // 対象区間は [l, r) にあたる
  ll getmax(int a, int b, int k=0, int l=0, int r=-1) {
    // 最初に呼び出されたときの対象区間は [0, n)
    if(r < 0) r = n;

    // 要求区間と対象区間が交わらない -> 適当に返す
    if(r <= a || b <= l) return -1;

    // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う
    if(a <= l && r <= b) return node[k];

    // 要求区間が対象区間の一部を被覆 -> 子について探索を行う
    // 左側の子を vl ・ 右側の子を vr としている
    // 新しい対象区間は、現在の対象区間を半分に割ったもの
    ll vl = getmax(a, b, 2*k+1, l, (l+r)/2);
    ll vr = getmax(a, b, 2*k+2, (l+r)/2, r);
    return max(vl, vr);
  }
};


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

   int N;
   ll M, V, P;
   cin >> N >> M >> V >> P;

   vector<ll> a(N);
   rep(i, N) cin >> a[i];

   sort(a.rbegin(), a.rend());

  int ans = 0;
  
  SegmentTree seg(a);

  vector<ll> suma(N+1);
  suma[0] = 0;
  rep(i, N){
    suma[i+1] = suma[i] + a[i];
  }

  rep(i, N){

    if(i < P){
      ans++;
      continue;
    }

    // i番目について
    // もし P-1 ~ i番目の最大値が a[i] + M より大きければだめ
    if(seg.getmax(P-1, i) > a[i] + M) continue;

    // 投票せざるをえない人たち

    ll H = max(0LL, V - (P-1 + (N-i)));

    if(H*M+suma[i]-suma[P-1] <= (a[i]+M)*(i-P+1)){
      ans++;
    }

  }

  cout << ans << endl;

  return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

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

  int n = s.size() + 1;
  vector<int> l(n, 0), r(n, 0);

  rep(i, s.size()) {
    if (s[i] == '<') {
      do {
        l[i + 1] = l[i] + 1;
      } while (++i < s.size() && s[i] == '<');
    }
  }

  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == '>') {
      do {
        r[i] = r[i + 1] + 1;
      } while (--i >= 0 && s[i] == '>');
    }
  }

  ll ans = 0;
  rep(i, n) {
    // cout << l[i] << ' ' << r[i] << endl;
    ans += max(l[i], r[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
void Fizz(int i,int n,unsigned long int sum){
    
    if(i == n){
        if(i%3 != 0 && i%5 != 0) sum+=i;
        cout << sum << endl;
    }
    else{
        if(i%3 != 0 && i%5 != 0){
            Fizz(i+1,n,sum+i);    
        }
        else{
            Fizz(i+1,n,sum);
        }
    }
}

int main() {
    
    int n;
    cin >> n;
    Fizz(1,n,0);
}

Measured memory_bytes: 3640
n = int(input())
t, x, y = 0, 0, 0
ans = "Yes"
for i in range(1, n+1):
  ti, xi, yi = map(int, input().split())
  displacements = (xi - x) + (yi - y)
  dist = abs(displacements)
  dt = ti - t
  if dt >= dist and (dt - dist) % 2 == 0:
    t, x, y = ti, xi, yi
  else:
    ans = "No"
 
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <sstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
const int MAXN = 2e5+10;
int N,M,Q;
int fa[MAXN];
int q[MAXN];
int p1[MAXN];
int p2[MAXN];
int find(int x)
{
    if(fa[x] == x) return x;
    return fa[x] = find(fa[x]);
}
void init()
{
    for(int i = 1;i <= N;i++){
        fa[i] = i;
    }
}
int main()
{
	N = read();M = read();Q = read();
	init();
	for(int i = 1;i <= Q;i++){
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        a++;
        b++;
        q[i] = c;
        p1[i] = a;
        p2[i] = b;
        if(c == 0){
            int aa = find(a);
            int bb = find(b);
            if(aa!=bb){
                fa[aa] = bb;
            }
        }
	}
	bool flag = 1;
	for(int i = 1;i <= Q;i++){
        if(q[i] == 1){
            flag = 0;
            if(find(p1[i]) == find(p2[i])){
                printf("No");
                return 0;
            }
        }
	}
	ll cnt = 0;
	for(int i = 1;i <= N;i++){
        if(fa[i] == i){
            cnt++;
        }
	}
	//cout<<cnt<<endl;
	ll maxn = cnt*(cnt-(ll)1)/(ll)2;
	ll ans = M - N + cnt;
	if(!flag&&ans>=max((ll)3,cnt)&&ans<=maxn){
//        if(cnt<=2){
//            printf("No");
//            return 0;
//        }
        printf("Yes");
	}
	else if(flag&&ans>=cnt-1&&ans<=maxn){
        printf("Yes");
	}
	else printf("No");
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Keep calm and carry on!
*/


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

int main() {
    double d;
    cin >> d;
    int d1 = d*1000;
    double ans = sqrt(2)*d;
    ans = max<double>(ans, (int)(d)+1);
    printf("%.10lf\n", ans);
    return 0;
}


Measured memory_bytes: 3292
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;


int main(){
  int N,M;
  ll temp;
  cin>>N>>M;
  pair<ll,int> p[210000];
  for(int i=0;i<N;i++){
    cin>>p[i].first;
    p[i].second=1;
    p[i].first*=-1;
  }
  for(int i=0;i<M;i++){
    cin>>p[N+i].second>>p[N+i].first;
    p[N+i].first*=-1;
  }
  sort(p,p+M+N);
  ll ans=0;
  int now=0;
  for(int i=0;i<N;i++){
    if(p[now].second!=0){
      p[now].second--;
      ans+=p[now].first*-1;
    }else{
      now++;
      ans+=p[now].first*-1;
      p[now].second--;
    }
    //cout<<ans<<endl;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int A, B;
  cin >> A >> B;
  bool bl = (A <= 9 && B <= 9);
  if (bl) {
    cout << A * B << '\n';  
  } else {
    cout << -1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int k, s;
int ans = 0;
int main()
{
    cin >> k >> s;
    for (int i = 0; i <= k; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            if (s - i - j <= k && s - i - j >= 0)
                ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

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

		ArrayList<ArrayList<Integer>> point = new ArrayList<ArrayList<Integer>>();
		
		int n = sc.nextInt();
		int d = sc.nextInt();
		
		for(int i = 0; i < n ; i++) {
			ArrayList<Integer> array = new ArrayList<Integer>();
			
			for (int j = 0; j < d ; j++) {
				
				array.add(sc.nextInt());
				
			}
			point.add(array);
		}
		
		
		
		
		int count= 0;
		
		for(int i = 0; i < n; i++) {
			
			for(int j = i+1 ; j < n; j++) {
				double distance = 0.0;
				for(int k = 0; k < d ; k++) {
					
					distance += Math.pow(point.get(i).get(k)-point.get(j).get(k), 2);
					
					
				}
				
				distance = Math.sqrt(distance);
				
				if(Math.ceil(distance) == Math.floor(distance)) {
					count++;
				}
				
			}
		}
		
		System.out.println(count);
		
		
	}

}


Measured memory_bytes: 23892
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
      d: i64,
    }
    print!("{}", "Christmas");
    for _ in 0..(d-25).abs() {
        print!("{}", " Eve");
    }
    println!();
}


Measured memory_bytes: 4352
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

/*-----<Defines>-----*/
#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)size(x))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)-1)/(x)+1)
#define     flush           fflush(stdout)

using ull=unsigned long long;
using ll=long long;
using ld=long double;
/*-----</Defines>-----*/

/*-----<Debugging Stuff>-----*/
string to_string(char s)
{   string res="'''";res[1]=s;return res; }

string to_string(string s)
{   return '"'+s+'"'; }

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

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

template<typename A, typename B>
string to_string(pair<A, B> p)
{   return "("+to_string(p.F)+", "+to_string(p.S)+")"; }

template<typename A>
string to_string(A v)
{
    bool first=1; string res="{";
    for(const auto &x:v)
    {
        if(!first)  res+=", ";
        first=0;
        res+=to_string(x);
    }
    res+="}";
    return res;
}

void debug() { cout<<"\n"; }
template<typename Head, typename... Tail>
void debug(Head H, Tail... T)
{
    cout<<" "<<to_string(H);
    debug(T...);
}

#define show(...) cout << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
/*-----</Debugging Stuff>-----*/

/*-----<Mod Operations>-----*/
const int M=1e9+7;
inline int add(int a,int b,int p=M){ a=a+b; if(a>=p) a-=p; return a; }
inline int sub(int a,int b,int p=M){ a=a-b; if(a<0) a+=p; return a; }
inline int mul(int a,int b,int p=M){ a=(a*1ll*b)%p; return a; }
/*-----</Mod Operations>-----*/

/*-----<Constants>-----*/
const ld pi=acos(-1),eps=1e-9;
const ll inf=1e18;
const int N=1;
/*-----</Constants>-----*/

void solve()
{
    int h,w,k;
    cin>>h>>w>>k;

    vector<string> mat(h);
    for(int i=0;i<h;++i)
        cin>>mat[i];

    int sum=h+w;
    int tot=1ll<<sum;

    int ans=0;
    for(int i=0;i<tot;++i)
    {
        int cnt=0;
        for(int j=0;j<h;++j)
        {
            for(int k=0;k<w;++k)
            {
                if(!(i&(1ll<<j)) && !(i&(1ll<<(h+k))) && mat[j][k]=='#')
                   ++cnt;
            }
        }

        if(cnt==k)
            ++ans;
    }

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 3652
# -*- coding: utf-8 -*-
import sys
import collections

def main():
	b = input()
	ans = "a"
	if b == 'A':
		ans = "T"
	if b == "T":
		ans = "A"
	if b == "C":
		ans = "G"
	if b == "G":
		ans = "C"
	
	
	print(ans)
			
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// int gcd(int a,int b){return b?gcd(b,a%b):a;}

bool VisitRed[110];

int main() {
  int n; cin >> n;
  vector<pair<int,int>> red; vector<pair<int,int>> blue;
  FOR(i,0,n-1){
    int a,b; cin >> a >> b;
    red.PB(MP(b,a));
  }
  sort(red.begin(),red.end(),greater<pair<int,int>>());
  FOR(i,0,n-1){
    swap(red[i].first,red[i].second);
  }

  FOR(i,0,n-1){
    int c,d; cin >> c >> d;
    blue.PB(MP(c,d));
  }
  SORT(blue);

  FOR(i,0,n-1){
    FOR(j,0,n-1){
      if(blue[i].first>red[j].first && blue[i].second>red[j].second && VisitRed[j]==false){
        VisitRed[j] = true;
        break;
      }
    }
  }

  int ans = 0;
  FOR(i,0,n-1){
    if(VisitRed[i]) ++ans;
  }

  cout << ans << endl;




  
}



Measured memory_bytes: 256
/**
        	C++14 (GCC 5.4.1)
**/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;

int main(){
    int N;

    cin >> N;

    cout << pow(N,3) << endl;
    return 0;
}

Measured memory_bytes: 384
#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;
use std::cmp::Ordering;

use proconio::input;
use proconio::marker::{Chars,Usize1,Isize1};

fn comp_f64(a: &f64, b: &f64) -> Ordering {
    if a < b {
        return Ordering::Less;
    } else if a > b {
        return Ordering::Greater;
    }
    Ordering::Equal
}

fn main() {
    input!{
        N:usize,
        A:[usize;N]
    }

    let mut C = vec![0;100_010];
    for &a in &A{
        C[a] += 1;
        if C[a]>2{C[a]-=2;}
    }

    let mut n1 = 0;
    let mut n2 = 0;
    for &c in &C{
        if c==1{
            n1 += 1;
        } else if c==2{
            n2 += 1;
        }
    }
    let ans = n1+n2 - n2%2;
    println!("{}",ans);
}

Measured memory_bytes: 3776
N = gets.chomp.to_i
X = gets.chomp.split(' ').map { |x| x.to_i }

if N == 1
  puts 0
  exit
end

puts (((X.min)..(X.max)).map do |x|
  (X.map { |xx| (xx - x).abs**2 }).reduce(:+)
end).min


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
	int n;
	cin>>n;
	cout<<n*n*n<<endl;
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define repa(i, a, b) for (auto i = (a); i <= (b); i++)
#define repd(i, a, b) for (auto i = (a); i >= (b); i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define zero(a)  memset((a), 0, sizeof (a))
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back

constexpr auto inf = numeric_limits<int>().max() - 1;
constexpr auto llinf = numeric_limits<ll>().max() - 1LL;

template<typename ForwardIterator>
void dump(ForwardIterator st, ForwardIterator en) {
  for (auto it = st; it != en; it++) {
    cout << *it << " ";
  }
  cout << endl;
}

template<typename ForwardIterator>
void dump_map(ForwardIterator st, ForwardIterator en) {
  for (auto it = st; it != en; it++) {
    cout << (*it).first << ":" << (*it).second << " ";
  }
  cout << endl;
}
template<typename T>
void debug(initializer_list<T> list) {
  for (auto el : list) {
    cout << el << " ";
  }
  cout << endl;
}

constexpr ll mod = ll(1e9 + 7);

ll mult(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }

ll power(ll a, ll b) {
  ll result = 1LL;
  while (b) {
    if (b % 2LL) result = mult(result, a);
    a = mult(a, a);
    b /= 2LL;
  }
  return result;
}

ll divide(ll a, ll b) { return mult(a, power(b, mod - 2)); }

ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }

ll subtract(ll a, ll b) { return ((a - b) % mod + mod) % mod; }

void solve() {
  int n, k;
  cin >> n >> k;
  vi h(n);
  for (auto &it : h) cin >> it;
  vi memo(n, -1);
  memo[0] = 0;
  function<int(int)> dp = [&] (int i) -> int {
    if (memo[i] != -1) return memo[i];
    int val = inf;
    for (int p = 1; p <= k; p++) {
      if (p <= i) {
        val = min(val, dp(i - p) + abs(h[i] - h[i - p]));
      } else {
        break;
      }
    }
    memo[i] = val;
    return val;
  };
  cout << dp(n - 1);
  cout << "\n";
}

#define REPEAT 0
#define CASE 0

int main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #if REPEAT
    int t;
    cin >> t;
    repa(i, 1, t) {
      #if CASE
        cout << "Case #" << i << ": ";
      #endif
      solve();
    }
  #else
    solve();
  #endif
  return 0;
}


Measured memory_bytes: 13496
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void)
{
    ll n, i = 0, A, a[200000];
    ll t = 0;

    cin >> n;

    while (cin >> A)
    {
        a[i] = A;
        // cout << a[i];
        i++;
    }
    for (i = 0; i < n-1 ; i++)
    {
        while (a[i] > a[i + 1])
        {
            a[i + 1] += 1;
            t++;
           // printf("a[%d]=",(i+1));
           //cout<<a[i+1]<<"\n";
           //cout <<"t="<< t<<"\n";
        }
    }
 
    cout << t;
}

Measured memory_bytes: 5156
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

string S;

int main(){
    cin>>S;

    rep(i,3){
        if(S[i]==S[i+1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }

    cout<<"Good"<<endl;
}

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

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

#define rep(i, a) for (int i=0; i<(a); i++) 
#define ub        upper_bound            // first element >  val(itr)
#define lb        lower_bound            // first element >= val(itr)

#define mp make_pair
#define pb push_back
#define pi 3.141592653589793
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define bitcount(a) __builtin_popcount(a) // count set bits
#define all(x) (x).begin(),(x).end()

const ll MOD = 1e9 + 7;
const int inf = 1e9+9;
const long long INF = 1e18+3;

//to debug 
#define dbg(x) cout << "Line " << __LINE__ << " | " #x ": " << (x) << endl

template<typename T> T gcd(T a,T b){ if(b>a) return gcd(b,a);return b==0?a:gcd(b,a%b); }
template<typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template<typename T> T fast_power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

inline ll mod(ll x,ll n) {if (x < n) return x; if (x >= n) return x - n;}
string IntToString(ll a){ ostringstream temp; temp << a; return temp.str();}
ll findMMI_fermat(ll n,ll M) {ll ans= fast_power(n,M-2,M);return ans;}//i.e In (a/b)%M..it calculates MMI of b wrt M
ll add(ll a,ll b,ll M)  { return ( mod(a,M ) + mod(b,M ))%M;     }
ll sub(ll a, ll b,ll M) { return (mod(a,M ) + M - mod(b,M ))%M;   }
ll mult(ll a,ll b,ll M) { return  ( mod(a,M)*mod(b,M) ) %M ; }
bool isprime(ll a){ if(a==2) {return 1;}if(!(a&1) ) {return 0;}for(ll i=3;i*i<=a;i+=2){if(a%i==0) {return 0;} } return 1;} 

  
               /* -------------------------------Main Code------------------------------- */

const int nx = 1005;
char sl[nx][nx];

void add_self(int &a,int b){
	a += b;
	if(a >= MOD){
		a-=MOD;
	}
}


int main(){
	FAST;
	int h,w;
	scanf("%d%d",&h,&w);
	for(int row=0;row<h;row++){
		scanf("%s",sl[row]);
	}
	vector<vector<int>> dp(h,vector<int>(w,0));
	dp[0][0] = 1;
	for(int col=1;col<w;col++){
		if(sl[0][col]=='#') break;
		else add_self( dp[0][col],dp[0][col-1] );
	}
	for(int row=1;row<h;row++){
		if(sl[row][0]=='#') break;
		else add_self( dp[row][0],dp[row-1][0] );
	}
	for(int row=1;row<h;row++){
		for(int col = 1;col<w;col++){
			if(sl[row][col] == '.'){
				add_self( dp[row][col] , dp[row-1][col] );
				add_self( dp[row][col] , dp[row][col-1] );
			}
		}
	}
	printf("%d", dp[h-1][w-1]);
	return 0;
}

	

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

int main(){
  int N,Y; cin >> N >> Y;
  int a=-1,b=-1,c=-1;
  
  for(int i=0; i<=N; i++){
    if(a!=-1) break;
    for(int j=0; j<=N-i; j++){
      if(a!=-1) break;
      if(10000*i+5000*j+1000*(N-i-j)==Y){
        a=i; b=j; c=N-i-j;
      }
    }
  }
  cout << a << " " << b << " " << c << 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;
using P = pair<int, int>;

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<char>> C(H, vector<char>(W));

  int sum = 0;
  rep(i, H) {
    rep(j, W) {
      char c;
      cin >> c;
      if (c == '#') sum++;
      C.at(i).at(j) = c;
    }
  }

  int ans = 0;
  for (int hi = 0; hi < (1 << H); hi++) {
    bitset<6> h(hi);
    string debug_h = h.to_string();
    int tmp_sum = sum;
    auto CC = C;

    rep(i, H) {
      if (h.test(i)) {
        rep(jj, W) {
          if (CC.at(i).at(jj) == '#') {
            tmp_sum--;
            CC.at(i).at(jj) = '.';
          }
        }
      }
    }

    if (tmp_sum < K) continue;

    for (int wj = 0; wj < (1 << W); wj++) {
      bitset<6> w(wj);
      string debug_w = w.to_string();
      int tmp_tmp_sum = tmp_sum;

      rep(j, W) {
        if (w.test(j)) {
          rep(ii, H) {
            if (CC.at(ii).at(j) == '#') {
              tmp_tmp_sum--;
              // CC.at(ii).at(j) = '.';
            }
          }
        }
      }

      if (tmp_tmp_sum == K) {
        ans++;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define pb push_back
#define mod int(1e9+7)
#define N int(2e5+100)
#define ll long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define si second
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int s,w;
	cin>>s>>w;
	cout<<((w>=s)?"unsafe":"safe")<<'\n';
   return 0;
}


Measured memory_bytes: 3648
#include <iostream>

int main() {

  int N;
  std::string S;
  int K;

  std::cin >> N >> S >> K;

  char tmp;
  tmp = S[K - 1];
  for (int i = 0; i < N; i++) {
    if (S[i] == tmp) {
      continue;
    } else {
      S[i] = '*';
    }
  }
  std::cout << S << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int n;
    int fx=0;
    scanf("%d", &n);
    int x = n;
    while(x){
        fx += x%10;
        x /= 10;
    }
    if(n%fx == 0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}

Measured memory_bytes: 128