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

int main(){
    int N, K;
    int i,j,k;
    int sum=0;
    double ans = 0.0;

    scanf("%d %d", &N, &K);

    for(i=1; i<=N; i++){
        sum = i;
        for(j=1; sum<K; j++){
            sum = sum * 2;
        }
        //printf("%lf",  1/(double)N * pow(0.5, j-1));
        ans += 1/(double)N * pow(0.5, j-1);
    }

    printf("%.16lf", ans);

    return 0;
}

Measured memory_bytes: 128
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
using namespace std;
static int imin = std::numeric_limits<int>::min();
static int imax = std::numeric_limits<int>::max();
#define ll long long
#define rep(i, n) for(int i = 0; i<n; ++i)
#define rep1(i, n) for(int i = 1; i<n; ++i)
template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  for(int i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template <class T>
auto mkVec(unsigned int x){
  return std::vector<int>(x);
}

template <class T>
auto mkVec2(unsigned int x, unsigned int y){
  return std::vector<std::vector<T>>(y, std::vector<T>(x));
}

template <class T>
auto mkVec3(unsigned int x, unsigned int y, unsigned int z){
  return std::vector<std::vector<std::vector<T>>>(z, std::vector<std::vector<T>>(y, std::vector<T>(x)));
}


#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  int N,  k;
  cin >> N >> k;
  vector<int> h;
  for(int i = 0; i<N; ++i){
    int x;
    cin >> x;
    h.push_back(x);
  }

  sort(h.begin(), h.end());
  int res = imax;
  for(int i = 0; i<N - k + 1; ++i){
    res = min(res, h[i + k - 1] -  h[i]);
  }
  cout << res;
}
#endif


Measured memory_bytes: 892
#include <iostream>

#define MAX_N 100000
#define MAX_Q 50000

int n, q;
int S[MAX_N], T[MAX_N];

bool binary_search(int t) {
    bool flag = false;
    int mid;
    int left=0, right=n-1;
    while (left <= right && !flag) {
        mid = (left + right) /2;
        if (t == S[mid]) {
            flag = true;
            break;
        } else if (S[mid] < t) {
            left = mid+1;
        } else { // S[mid] > t
            right = mid-1;
        }
    }
    return flag;
}

int main() {
    int res=0;
    std::cin >> n;
    for (int i=0; i<n; i++) std::cin >> S[i];
    std::cin >> q;
    for (int i=0; i<q; i++) {
        std::cin >> T[i];
        if ( binary_search(T[i]) ) res++;
    }
    std::cout << res << std::endl;

    return 0;
}



Measured memory_bytes: 3668
class Node:
    def __init__(self, parent, left, right):
        self.parent, self.left, self.right = parent, left, right

T = {}
root = None

def insert_node(key):
    global root
    x = root
    y = None
    z = Node(None, None, None)
    while x != None:
        y = x
        if key < x:
            x = T[x].left
        else:
            x = T[x].right
    z.parent = y
    if y == None:
        root = key
    else:
        if key < y:
            T[y].left = key
        else:
            T[y].right = key
    T[key] = z

def find_node(key):
    x = root
    while x != None and key != x:
        if key < x:
            x = T[x].left
        else:
            x = T[x].right
    if x != None:
        print('yes')
    else:
        print('no')

def in_print(key, ls):
    if key == None:
        return
    in_print(T[key].left, ls)
    ls.append(key)
    in_print(T[key].right, ls)

def pre_print(key, ls):
    if key == None:
        return
    ls.append(key)
    pre_print(T[key].left, ls)
    pre_print(T[key].right, ls)

def print_node():
    in_ls, pre_ls = [], []
    in_print(root, in_ls)
    pre_print(root, pre_ls)
    print('', *in_ls)
    print('', *pre_ls)

N = int(input())
for i in range(N):
    com = input().split()
    if com[0] == 'insert':
        insert_node(int(com[1]))
    if com[0] == 'find':
        find_node(int(com[1]))
    elif com[0] == 'print':
        print_node()


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

class Program
{
    static void Main()
    {
        int[] l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int r = l[0], c = l[1];
        int[] cans = new int[c + 1];
        string ans = "";

        for (int i = 0; i < r; i++)
        {
            int[] o = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int a = 0;

            for (int j = 0; j < c; j++)
            {
                cans[j] += o[j];
                ans += o[j] + " ";
                a += o[j];
            }

            cans[c] += a;
            ans += a + "\r\n";
        }
        for (int i = 0; i < c; i++)
        {
            ans += cans[i] + " ";
        }
        ans += cans[c];

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 10084
n = gets.to_i
dp = n.times.map{Array.new(3, 0)}

a, b, c = 0, 0, 0

n.times do |i|
  abc = gets.split.map(&:to_i)
  if i == 0
    3.times do |j|
      dp[i][j] = abc[j]
    end
  else
    dp[i][0] = abc[0] + ((b > c) ? b : c) 
    dp[i][1] = abc[1] + ((a > c) ? a : c) 
    dp[i][2] = abc[2] + ((a > b) ? a : b) 
  end
  a = dp[i][0]
  b = dp[i][1]
  c = dp[i][2]
end

puts dp[n - 1].max


Measured memory_bytes: 9340
import java.util.*;

public class Main
{
	public static void main (String[] args) 
	{
		
		Scanner scn = new Scanner(System.in);
    Map<Integer,Integer> map = new HashMap<Integer,Integer>();
    int n = scn.nextInt();
    int []arr = new int[n];
    for(int i=1;i<n;i++){
      arr[i] = scn.nextInt();
    }
    for(int i=1;i<arr.length;i++){
      if(map.containsKey(arr[i])){
        int val = map.get(arr[i]) + 1;
        map.put(arr[i],val);
      }else{
        map.put(arr[i],1);
      } 
 }
 
  for(int i=1;i<arr.length;i++){
  	if(map.containsKey(i)){
    int val = map.get(i);
    System.out.println(val);
  	}
    else
    System.out.println(0);
    
  }
      System.out.println(0);
		
		
	}
}

Measured memory_bytes: 72392
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls int
#define give main()
const int mod = 1000000007;
#pragma endregion

const int N = 1e6+5;
double arr[200000+5];
pls give {
    AC;
    int n, k;
    cin >> n >> k;
    for (int i=1; i<=n; i++) {
        cin >> arr[i];
        arr[i] = (arr[i]+1)/2;
        arr[i] += arr[i-1];
    }
    double ms=0;
    for (int i=0; i<=n-k; i++) {
        ms = max(arr[i+k] - arr[i], ms);
    }
    cout << fixed << setprecision(10) << ms << nl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int n;
  scanf("%d", &n);

  if (n % 2 == 0) printf("%d", n);
  else printf("%d", 2 * n);
  return 0;
}


Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char) 
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let (a, b, c, k): (i64, i64, i64, i64) = (read(), read(), read(), read());

  use std::cmp;
  let max = cmp::min(a, k) - cmp::min(c, cmp::max(0, k - b - a));
  println!("{}", max);
}

Measured memory_bytes: 2104
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

int main(){

	int left_length,right_length,max,tmp,left_start,left_end,right_start,right_end,k;
	char left[4001],right[4001];

	while(scanf("%s",left) != EOF){
		scanf("%s",right);

		for(left_length = 0;left[left_length] != '\0';left_length++);
		for(right_length = 0; right[right_length] != '\0';right_length++);

		max = 0;
		if(right_length > left_length){

			//left???????????¨right???????????????????????§
			for(right_end = 1;right_end <= left_length;right_end++){
				tmp = 0;
				for(left_start = left_length-right_end,k=0; k < right_end; k++){
					if(left[left_start+k] == right[k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			//left???????????¨right???????????????????????§
			for(right_end = left_length;right_end < right_length;right_end++){
				tmp = 0;
				for(right_start = right_end-left_length,k=0;right_start + k < right_end; k++){
					if(left[k] == right[right_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			//left_end???0??????????????§
			for(left_end = left_length-1;left_end >= 1; left_end--){
				tmp = 0;
				for(right_start = right_length-left_end,k=0;k < left_end; k++){
					if(left[k] == right[right_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

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

		}else{

			//right???????????¨left???????????????????????§
			for(left_end = 1;left_end <= right_length;left_end++){
				tmp = 0;
				for(right_start = right_length-left_end,k=0; k < left_end; k++){
					if(right[right_start+k] == left[k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			//right???????????¨left???????????????????????§
			for(left_end = right_length;left_end < left_length;left_end++){
				tmp = 0;
				for(left_start = left_end-right_length,k=0;left_start + k < left_end; k++){
					if(right[k] == left[left_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			//right_end???0??????????????§
			for(right_end = right_length-1;right_end >= 1; right_end--){
				tmp = 0;
				for(left_start = left_length-right_end,k=0;left_start + k < left_length; k++){
					if(right[k] == left[left_start+k]){
						tmp++;
						max = (max >= tmp)?max:tmp;
					}else{
						tmp = 0;
					}
				}
			}

			printf("%d\n",max);
		}
	}

	return 0;
}

Measured memory_bytes: 2652
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 T = sc.nextInt();
		if (N%X==0) {
			System.out.println(N/X*T);
		} else {
			System.out.println(N/X*T+T);
		}
	}
}

Measured memory_bytes: 35644
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  string s; cin >> s;
  string s1{s.rbegin(), s.rend()};
  if (s != s1) {
    cout << "No" << CRLF;
    return;
  }
  int N = s.size();
  string s2 = s.substr(0, (N-1)/2);
  string s21{s2.rbegin(), s2.rend()};
  if (s2 != s21) {
    cout << "No" << CRLF;
    return;
  }
  int k = (N+3) / 2;
  string s3 = s.substr(k-1, N);
  string s31{s3.rbegin(), s3.rend()};
  if (s3 != s31) {
    cout << "No" << CRLF;
    return;
  }
  cout << "Yes" << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

using namespace std;

class Team{
public:
  int id, pr, pe;
  Team(){}
  Team(int id, int pr, int pe): id(id), pr(pr), pe(pe){}
  bool operator < (const Team &t) const {
    if(pr != t.pr) return pr > t.pr;
    if(pe != t.pe) return pe < t.pe;
    return id > t.id;
  }
  bool operator == (const Team &t) const {
    return pr == t.pr && pe == t.pe;
  }
};

const int N = 50;

int M, T, P, R;
bool sc[N][10];
int cnt[N][10];
Team team[N];

main(){
  while(cin >> M >> T >> P >> R && (M|T|P|R)){
    for(int i=0;i<T;i++) team[i] = Team(i, 0, 0);
    fill(sc[0], sc[N], false);
    fill(cnt[0], cnt[N], 0);
    for(int i=0;i<R;i++){
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--; p--;
      if(j) cnt[t][p]++;
      else if(!sc[t][p]){
        sc[t][p] = true;
        team[t].pr++;
        team[t].pe += m + 20 * cnt[t][p];
      }
    }
    sort(team, team+T);
    cout << team[0].id+1;
    for(int i=1;i<T;i++) cout << (team[i-1] == team[i] ? '=' : ',') << team[i].id+1;
    cout << endl;
  }
}

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

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N = sc.nextInt();
	static int A = sc.nextInt();
	static int B = sc.nextInt();
	static int[] P = new int[N];
	static {
		Arrays.setAll(P, i -> sc.nextInt());
	}
	public static void main(String[] args) {
		int count1 = 0;
		int count2 = 0;
		int count3 = 0;
		for (int i = 0; i < P.length; i++) {
			if (P[i]<=A) {
				count1++;
			}
			if (P[i]>A && P[i] <= B) {
				count2++;
			}
			if (P[i] > B) {
				count3++;
			}
		}
		int ans = Math.min(count1, Math.min(count2, count3));
		System.out.println(ans);
	}
}

Measured memory_bytes: 30036
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	long N;
	cin >> N;
	long K;
	cin >> K;
	vector<long> avec;
	vector<long> zeros;
	for (long i = 0; i < N; ++i)
	{
		long a;
		cin >> a;
		avec.emplace_back(a);
		if (a == 0)
		{
			zeros.emplace_back(i);
		}
	}

	unsigned int currentZeroIdx = 0u;
	int currentZero = -1;
	if (zeros.size() > 0)
	{
		currentZero = zeros[currentZeroIdx];
	}
	for (long i = K; i < N; ++i)
	{
		if ((zeros.size() > 0) && currentZero < i - K + 1)
		{
			currentZeroIdx++;
			if (zeros.size() - 1 < currentZeroIdx)
			{
				currentZero = -1;
			}
			else
			{
				currentZero = zeros[currentZeroIdx];
			}
		}

		if ((currentZero != -1) && (i - K + 1 <= currentZero && currentZero < i))
		{
			cout << "No" << endl;
		}
		else
		{ 
			if (avec[i] > avec[i - K])
			{
				cout << "Yes" << endl;
			}
			else
			{
				cout << "No" << endl;
			}
		}
	}
}

Measured memory_bytes: 5364
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

// 容量Wのナップサックに、
//   価値 : v[i], 重さ : w[i]
// の品物を個数制限なしに詰めるときの価値の最大値
ll knapsack(ll W, vector<int> v, vector<int> w){
    const int n = v.size();
    vector<vector<ll>> dp(2, vector<ll>(W + 1, 0LL));
    for (int i = 1; i <= n; ++i){
        for (int j = 0; j <= W; ++j){
            ll tmp = dp[(i - 1) & 1][j];
            if (j - w[i - 1] >= 0 && j - w[i - 1] <= W)
                tmp = max(dp[i & 1][j - w[i - 1]] + v[i - 1], tmp);
            dp[i & 1][j] = tmp;
        }
    }
    return dp[n & 1][W];
}

int main(void){
    ll N; cin >> N;
    int ga, sa, ca; cin >> ga >> sa >> ca;
    int gb, sb, cb; cin >> gb >> sb >> cb;
    N += knapsack(N, {(gb - ga), (sb - sa), (cb - ca)}, {ga, sa, ca});
    N += knapsack(N, {(ga - gb), (sa - sb), (ca - cb)}, {gb, sb, cb});
    cout << N << endl;
    return 0;
}

Measured memory_bytes: 586368
#include <iostream>
#include <string>

using namespace std;

int main() {

	long long int a, b, c, k, ans;
	cin >> a >> b >> c >> k;

	if (a < k) {
		ans = a;
		k -= a;
		k -= b;
		if (k > 0) ans -= k;
	}
	else ans = k;

	cout << ans;

	return 0;
}




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

using namespace std;

#define ll long long int
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<ll>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.14159265
#define pb push_back
#define bits(n) __builtin_popcount(n)

void solve()
{
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(u==s)
    a--;
    else
    {
        b--;
    }
    cout<<a<<" "<<b;

}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t=1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}

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

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int oo = 1e9 + 7;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a, b, t, ans = 0, w;
  cin >> a >> b >> t;
  w = a;
  while (w <= t) {
    ans += b;
    w += a;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	int[] h = new int[n];
      	for (int i = 0; i < n; i++){
        	h[i] = scan.nextInt();
        }
      	int max = h[0];
      	int counter = 1;
      	for (int j = 0; j < n - 1; j ++){
        	if(max <= h[j + 1]){
            	max = h[j + 1];
              	counter++;
            }
        }
      	System.out.print(counter);
    
    }
 
}

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

int main()
{
  ll a, b, k;
  cin >> a >> b >> k;
  if (a >= k)
  {
    cout << a - k << " " << b << endl;
  }
  else if (b >= k - a)
  {
    cout << 0 << " " << b - k + a << endl;
  }
  else
  {
    cout << 0 << " " << 0 << endl;
  }
}


Measured memory_bytes: 3612
package main

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

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	r, c := nextInt(), nextInt()
	a := make([][]int, r+1)
	for i := 0; i < r+1; i++ {
		a[i] = make([]int, c+1)
	}
	for i := 0; i < r; i++ {
		for j := 0; j < c; j++ {
			a[i][j] = nextInt()
			a[i][c] += a[i][j]
			a[r][j] += a[i][j]
		}
	}
	for i := 0; i <= r; i++ {
		for j := 0; j <= c; j++ {
			if i == r && j != c {
				a[r][c] += a[i][j]
			}
			fmt.Printf("%d", a[i][j])
			if j != c {
				fmt.Printf(" ")
			}
		}
		fmt.Println("")
	}
}



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

const int mod = 1000000007;
//const int mod = 998244353;

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

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


int main()
{
    int n;
    cin >> n;
    vector<pair<string, P>> s(n);
    rep(i, 0, n){
        cin >> s[i].first >> s[i].second.first;
        s[i].second.first *= -1;
        s[i].second.second = i + 1;
    }
    sort(s.begin(), s.end());
    rep(i, 0, n){
        cout << s[i].second.second << endl;
    }
    return 0;
}


Measured memory_bytes: 3640
n, *a_l = map(int, open(0).read().split())
multi_4 = sum([1 for a in a_l if a%4 == 0])
multi_2 = sum([1 for a in a_l if a%2 == 0]) - multi_4
multi_1 = n - ( multi_2 + multi_4 )
print('Yes' if (multi_2%2 + multi_1) <= multi_4 + 1 else 'No')

Measured memory_bytes: 14052
#include<iostream>
#include<vector>
#include<algorithm>
typedef unsigned long long ull;
using namespace std;
int main(){
	int N;
	cin >> N;
	int count = 0;
	string str="ABC";
	while(N>999){
		N-=999;
		str[2]++;
	}
	cout << str << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define MAX 100000
typedef long long ll;
using namespace std;

ll N, K;

int main()
{
  cin >> N >> K;

  ll cnt[MAX+100] = {0};

  ll total_cnt = 0;

  for (size_t i = 0; i < N; ++i) {
    ll a_tmp;
    ll b_tmp;
    cin >> a_tmp >> b_tmp;
    cnt[a_tmp] += b_tmp;
  }

  for (size_t i = 1; i < MAX+1; ++i) {
    total_cnt = total_cnt + cnt[i];
    if (total_cnt >= K) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 1024
n, q = map(int, input().split())
pl = []
xl = []
parent = {}
for i in range(1, n):
    a, b = map(int, input().split())
    parent[b] = a
for i in range(q):
    p, x = map(int, input().split())
    pl.append(p)
    xl.append(x)

node = {}
for i in range(1, n+1):
    node[i] = 0
for j in range(q):
    node[pl[j]] += xl[j]


def find(parent, mem, node, i):
    if mem[i] != -1:
        return mem[i]
    if i == 1:
        mem[i] = node[i]
        return mem[i]
    mem[i] = node[i] + find(parent, mem, node, parent[i])
    return mem[i]


mem = [-1]*(n+1)
ans = []
for i in range(1, n+1):
    ans.append(find(parent, mem, node, i))
print(*ans)


Measured memory_bytes: 90500
str_N = input()
digits = len(str_N)
N = int(str_N)


seq = [3,5,7]

memo = [0] * digits
memo[0] = [(3,), (5,), (7,)]
count = 0
for n in range(2, digits+1):
    index = n - 1
    memo[index] = []
    before_digit = n - 1
    before_index= index - 1
    before_357s = memo[before_index]
    for before_357 in before_357s:
        for sgn in seq:
            memo[index].append(tuple(list(before_357) + [sgn]))
    memo[index] = list(set(memo[index]))

    ans_list = filter(lambda t: 3 in t and 5 in t and 7 in t, memo[index])
    ans_list = map(lambda t: int(''.join(list(map(lambda i: str(i), t)))), ans_list)
    ans_list = list(filter(lambda n: n <= N, ans_list))
    count += len(ans_list)

print(count)

Measured memory_bytes: 8200
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

int main(){
  int N;
  cin >> N;
  int L[N];
  rep(i, N)
    cin >> L[i];
  //

  int ans = 0;
  rep(i, N-2){
    for(int j=i+1; j<N-1; j++){
      for(int k=j+1; k<N; k++){
	if(L[i]==L[j] || L[j]==L[k] || L[k]==L[i])
	  continue;
	if(abs(L[i]-L[j]) < L[k] )
	  if(L[k]<L[i]+L[j]){
	    ans++;
	  }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        s: chars,
    }
    let mut t = true;
    let mut f = 0;
    let mut b = 0;
    for i in 0..s.len() {
        if t && s[i] == 'A' {
            f = i;
            t = false;
        } else if s[i] == 'Z' {
            b = i;
        }
    }
    println!("{}", b - f + 1);
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    LL N;
    cin >> N;
    vector<LL> L(N + 1);
    L[0] = 2;
    L[1] = 1;
    FOR(i, 2, N + 1) {
        L[i] = L[i - 1] + L[i - 2];
    }
    cout << L[N] << endl;
    return 0;
}



Measured memory_bytes: 256
import bisect
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort()
B.sort()
C.sort()
ans = 0

for i in range(N):

    count_a = bisect.bisect_left(A,B[i])
    count_c = N -bisect.bisect_right(C,B[i])
    ans += count_a*count_c
    
print(ans)

Measured memory_bytes: 23232
#include <stdio.h>

int CalcID(int r, int t) { return r + 5*t; }

int main() {

    int i, n, r, t, onR, onT;
    scanf("%d", &n);
    for ( i=0; i<n; ++i ) {

	scanf("%d %d", &r, &t);

	onR = r%100 == 0;
	onT = t%30 == 0;
	r /= 100;
	t /= 30;

	if ( onR && onT ) printf("%d\n", CalcID(r, t));
	else if ( onR ) printf("%d %d\n", CalcID(r, t), CalcID(r, t+1));
	else if ( onT ) printf("%d %d\n", CalcID(r, t), CalcID(r+1, t));
	else {
	    printf("%d %d %d %d\n", CalcID(r, t), 
		   CalcID(r+1, t), CalcID(r, t+1), CalcID(r+1, t+1));
	}
    }

    return 0;
}



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

vector <string> s;
vector <string> ans; 
int n;
void dfs(int com,int a,int b,int c)
{
    if(a<0 or b<0 or c<0)
        return;
    if(com==n+1){
        cout<<"Yes\n";
        for(int i=1;i<=n;i++)
        {
            cout<<ans[i]<<'\n';
        }
        exit(0);
    }
    if(s[com]=="AB")
    {
        ans[com]="A";
        dfs(com+1,a+1,b-1,c);
        ans[com]="B";
        dfs(com+1,a-1,b+1,c);
    }
    else if(s[com]=="AC")
    {
        ans[com]="A";
        dfs(com+1,a+1,b,c-1);
        ans[com]="C";
        dfs(com+1,a-1,b,c+1);
    }
    else
    {
        ans[com]="B";
        dfs(com+1,a,b+1,c-1);
        ans[com]="C";
        dfs(com+1,a,b-1,c+1);
    }
}


int main()
{
    int i,a,b,c;
    cin>>n>>a>>b>>c;
    s.resize(n+1);
    ans.resize(n+1);
    for(i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    dfs(1,a,b,c);
    cout<<"No";
    return 0;
}


Measured memory_bytes: 17224
#include <bits/stdc++.h>
using namespace std;
 
// a,b,cの最大値、最小値をそれぞれminimumの参照先、maximumの参照先に代入する

int main() {
    int64_t N,A,B;
    cin >> N >>A>>B;
    int64_t iterAmount = A+B;
    int64_t iterNum = N / iterAmount;
    int64_t remain = N - iterNum * iterAmount;

    int64_t result =0;
    result += iterNum *A;
    if(remain){
        // result+=1000;
        if(remain<A){
            result +=remain;
        }
        else {
            result +=A;
        }
    }


    cout << result <<endl;

}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		for (double i = 1; i <= n; i++) {
			if ((int)(i * 1.08) == n) {
				System.out.println((int)i);
				return;
			}
		}
		System.out.println(":(");
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 22996
s = input()
a = []
#n=[s[i] for i in range(len(s))]

for i in range(len(s)): 
    if len(a)>0 and s[i]=="B":
        a.pop(-1)
    elif s[i]=='0':
        a.append('0')
    elif s[i]=='1':
        a.append('1')
answer=""
for i in range(len(a)):
    answer += a[i]

print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();

    int max_len = 0;
    int now_end = n-1;
    if(n %2 == 0 ) {now_end-=2;}
    else  now_end-=1; 
    while(now_end > 0) {
        bool ok = true;
        int j = (now_end+1)/2;
        rep(i, j) if(s[i] != s[i+j]) ok = false;
        if(ok == true) {
            max_len = now_end+1;
            break;
        }
        now_end-=2;
    }
    cout << max_len << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

int X[10][10];

int main() {
	int N, D;

	cin >> N >> D;

	for(int i=0; i<N; i++) {
		for(int j=0; j<D; j++) {
			cin >> X[i][j];
		}
	}


	int sum = 0;
	int cnt = 0;
	for(int i=0; i<N; i++) {
		for(int j=i+1; j<N; j++) {
			sum = 0;
			for(int z=0; z<D; z++) {
			 	sum += abs(X[i][z]-X[j][z])*abs(X[i][z]-X[j][z]);
			}
			float tmp = sqrt((float)sum);
			if(ceil(tmp) == floor(tmp)) { // int
				cnt++;
			}
		}
	}
	cout << cnt;

}

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

int s[100000], n;

int binsearch(int key) {
	int left = 0, right = n, mid = (left + right)/2;
	while(left < right) {
		if(s[mid] == key) return 1;
		else if(s[mid] > key) {
			right = mid;
			mid = (left + right)/2;
		} else if(s[mid] < key) {
			left = mid+1;
			mid = (left + right)/2;
		}
	}
	return 0;
}

int main() {
	int m, count = 0;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> s[i];
	}
	cin >> m;
	for(int i = 0; i < m; i++) {
		int t;
		cin >>t; 
		count += binsearch(t);
	}
	cout << count <<endl;
	return 0;
}

Measured memory_bytes: 1548
import numpy as np

N = input()
T, A = map(int, input().split())
H_list = []
H_list = list(map(int, input().split()))
T_list = list(map(lambda x : T - (x * 0.006), H_list))
T_list_2 = np.array(list(map(lambda x : abs(x - A), T_list)))
index = np.argmin(T_list_2)
print(index + 1)

Measured memory_bytes: 21400
//#include "bits/stdc++.h"

#include <iostream>
#include <vector>
#include <set>
// #include <map>
#include <string>
// #include <numeric>
// #include <limits>

using namespace std;

int n;
vector<string> log;
set<int> bar;

void input() {
	log.clear();
	bar.clear();
	for (int i = 0; i < n; i++) {
		string tmp;
		cin >> tmp;
		log.push_back(tmp);
	}
}

void draw(int key) {
	string& str = log[key];
	if (isalpha(str[0])) {
		return;
	}
	size_t pos;
	for (pos = 0; pos < str.size(); pos++) {
		if (str[pos + 1] != '.') {
			break;
		}
	}
	str[pos] = '+';
	for (int i = key - 1; i >= 0; i--) {
		string& target = log[i];
		if (target.size() < pos or target[pos] != '.') {
			break;
		}
		log[i][pos] = '|';
	}
}

void print(const string& str) {
	for (auto c : str) {
		if (c == '.') {
			cout << ' ';
		} else {
			cout << c;
		}
	}
	cout << endl;
}

void solve() {
	input();
	for (int i = 0; i < n; i++) {
		draw(i);
	}
	for (auto str : log) {
		print(str);
	}
}

int main() {

	while (true) {
		cin >> n;
		if (n == 0) {
			break;
		}
		solve();
	}


	//std::cout << "\e[38;5;0m\e[48;5;40m --- end ---  \e[m" << std::endl; // debug
	return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	int N, M, A, B;
	cin >> N;

	if (N == 1) co("Hello World");
	else {
		cin >> A >> B;
		co(A + B);
	}
	Would you please return 0;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","w",stdout);
    //FILE *fptr2=freopen("out.txt","w",stdout);


string s;
cin>>s;
int a=0,b=0;
for(auto ch:s)
{
    if(ch=='A') a++;
    else b++;
}

if(a==2 or b==2) cout<< "Yes";
else cout<< "No";



    return 0;
}


Measured memory_bytes: 3592
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 1000000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
vector<int> G[100001];

int func(int v,int p){
	int cnt=0;
	vector<int> val;
	for(int i=0;i<G[v].size();i++){
		if(G[v][i]!=p){
			val.push_back(func(G[v][i],v));
			cnt++;
		}
	}
	if(cnt==0)return 0;
	sort(val.begin(),val.end());
	int res=0;
	for(int i=0;i<val.size();i++){
		res=max(res,val[i]+cnt-i);
	}
	return res;
}

int main(void){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int a;
		scanf("%d",&a);
		a--;
		G[a].push_back(i);
	}
	printf("%d\n",func(0,-1));
	return 0;
}


Measured memory_bytes: 16640
fun main() {
  var (A, B, C, D) = readInts()
  while (true) {
    C -= B
    if (C <= 0) {
      println("Yes")
      break
    }
    A -= D
    if (A <= 0) {
      println("No")
      break
    }
  }
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 36412
n,m,l = map(int, input().split())
wf=[[float("inf") for i in range(n)] for j in range(n)]
for i in range(m):
    a,b,c = list(map(int,input().split()))
    wf[a-1][b-1] = c
    wf[b-1][a-1] = c
q = int(input())
st=[list(map(int,input().split())) for i in range(q)]

from scipy.sparse.csgraph import floyd_warshall
for i in range(n):
    wf[i][i]=0
wf=floyd_warshall(wf)

for i in range(n):
    for j in range(n):
        if wf[i][j] <= l:
            wf[i][j] = 1
        else:
            wf[i][j] = float("inf")

wf=floyd_warshall(wf)

for que in st:
    s,t=que
    if wf[s-1][t-1] == float("inf"):
        print(-1)
    else:
        print(int(wf[s-1][t-1]-1))

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

int main()
{
    ll a[4];
    cin>>a[0]>>a[1]>>a[2]>>a[3];
    ll sum=LONG_MIN;
    for(int i=0;i<2;i++)
    {
        for(int j=2;j<4;j++)
        {
            sum= max(sum,a[i]*a[j]);
        }
    }
    cout<<sum<<endl;
}



Measured memory_bytes: 3628
#include <stdio.h>
#define MAX 2000001
  
int h = 0;

void MaxHeapify(int *a, int i){
  int left, right, large, change;
  
  if(i*2<=h){
    left=i * 2;
  }
  else left = i;
  if(i*2+1<=h){
    right=i*2+1;
  }
  else right = i;
  
  
  if(left < h + 1 && a[left] > a[i]) large = left;
  else large = i;
  if(right < h + 1 && a[right] > a[large]) large = right;
    
  if(large != i){
    change = a[i];
    a[i] = a[large];
    a[large] = change;
    MaxHeapify(a, large);
  }
}

void Insert(int *a, int key){
  int i, change;
  
  h++;
  i=h;
  a[i]=key;
  while(i>1 && a[i/2]<a[i]){
    change=a[i];
    a[i]=a[i/2];
    a[i/2]=change;
    i=i/2;
  }
}
  
void ExtractMax(int *a){
  int m;
  
  m=a[1];
  a[1]=a[h];
  h--;
  MaxHeapify(a, 1);
  
  printf("%d\n",m);
}

int main(){
  int a[MAX], key;
  int i=0, j;
  char str[8];
  
  while( 1 ){
    scanf("%s",str);
    if(str[2] == 'd') break;
    else if(str[0] == 'i'){
      scanf("%d", &key);
      Insert(a, key);
    }
    else ExtractMax(a);
  }
  return 0;
}

Measured memory_bytes: 5032
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cstdio>
#include <random>
#include <chrono>
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define int long long
using namespace std;

const int INF = 2e15;
const int MOD = 998244353;
int MB = 20;



void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	vector<int> dp(n);
	for (int i = 1; i < n; i++) {
		int mn = INF;
		for (int j = i - 1; j >= max(0LL, i - k); j--) {
			mn = min(mn, dp[j] + abs(h[i] - h[j]));
		}
		dp[i] = mn;
	}
	cout << dp[n - 1];
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

Measured memory_bytes: 1792
import java.util.HashMap;
import java.util.Scanner;

public class Main {

    public Main() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        HashMap<Integer, Integer> counter = new HashMap<>();
        for (int i = 0; i < N; i++){
            int key = scanner.nextInt();
            counter.put(key, counter.getOrDefault(key,0) + 1);
        }

        if (counter.containsKey(1)){
            if (counter.get(1) == 1){
                System.out.println(1);
            } else {
                System.out.println(0);
            }
            return;
        }

        long R = 0L;
        for (int key : counter.keySet()) {
            boolean isOK = true;

            if (counter.get(key) > 1) continue;

            for (int i = 2; i*i <= key; i++) {
                if (key%i == 0){
                    if(counter.containsKey(i) || counter.containsKey(key/i)){
                        isOK = false;
                        break;
                    }
                }
            }

            if (isOK) R += (long)counter.get(key);
        }

        System.out.println(R);
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 72164
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main()
{
    int R;
    cin >> R;
    if (R < 1200)
    {
        cout << "ABC" << endl;
    }
    else if (R < 2800)
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "AGC" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import sys
n,m=map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
for i in range(10**n):
  if len(str(i)) < n:
    continue
  for j in range(m):
    sti = str(i)
    if sti[sc[j][0]-1] != str(sc[j][1]):
      break
  else:
    print(i)
    sys.exit()
print(-1)

Measured memory_bytes: 3064
s = input()
n = int(input())
for i in range(n):
    tmp = input().split()
    if tmp[0] == 'print':
        a = int(tmp[1])
        b = int(tmp[2])
        print(s[a:b+1])
    elif tmp[0] == 'reverse':
        a = int(tmp[1])
        b = int(tmp[2])
        c = s[a:b+1]
        r = c[::-1]
        s = s[:a] + r + s[b+1:]
    elif tmp[0] == 'replace':
        a = int(tmp[1])
        b = int(tmp[2])
        p = tmp[3]
        s = s[:a] + p + s[b+1:]


Measured memory_bytes: 5608
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int Alice = 0;
	int Bob = 0;
	sort(a.begin(), a.end(), greater<int>());
	rep(i, n) {
		if (i % 2 == 0)Alice += a[i];
		else Bob += a[i];
	}
	cout << Alice - Bob << endl;
}

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

struct Edge;
struct Node{
	Edge *head;
	int col;
	Node():col(-1){}
}node[100010];
struct Edge{
	Node *to;
	Edge *ne;
	Edge(int x, int y) : to(&node[y]), ne(node[x].head){}
};
int N, M, w, b;
bool fl=true;

void dfs(Node *x){
	if(x->col==0)	w++;
	else			b++;
	for(Edge *i=x->head; i; i=i->ne)
		if(i->to->col==-1){
			i->to->col=x->col^1;
			dfs(i->to);
		}else if(i->to->col==x->col) fl=false;
}

int main(){
	int x, y;
	scanf("%d%d", &N, &M);
	for(int i=1; i<=M; i++){
		scanf("%d%d", &x, &y);
		node[x].head=new Edge(x, y);
		node[y].head=new Edge(y, x);
	}
	node[1].col=1;
	dfs(&node[1]);
//	cout<<fl<<" "<<w<<" "<<b<<endl;
	if(fl)
		printf("%lld", (long long)w*b-M);
	else
		printf("%lld", (long long)N*(N-1)/2-M);
	return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    bool r=a<=8 && b<=8;
    if(r){
        cout << "Yay!\n";
    } else{
        cout << ":(\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	ld d, x;
	scanf("%d%Lf%Lf", &n, &d, &x);
	ld ans = 0;
	while (n) {
		ans += d + (2 * n - 1) / 2.L * x;
		d = (1 + 1.L / n) * d + 2.5L * x / n;
		x = (1 + 2.L / n) * x;
		--n;
	}
	printf("%.9Lf\n", ans);
}

Measured memory_bytes: 3796
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <set>
using namespace std;



int main(){
    int n,MAX = 100010,ans;
    cin >> n;
    vector<int> odd(MAX),even(MAX);
    fill(odd.begin(), odd.end(), 0);
    fill(even.begin(), even.end(), 0);
    for (int i = 1; i <= n; i++) {
        int v;
        cin >> v;
        if(i%2==0) even[v]++;
        else odd[v]++;
    }
    int oddnum, evennum, omax1 = 0, omax2 = 0, emax1 = 0, emax2 = 0;
    for (int i = 0; i < 100010; i++) {
        if(omax1 < odd[i]){
            omax2 = omax1;
            omax1 = odd[i];
            oddnum = i;
        }
        else if(omax2 < odd[i]){
            omax2 = odd[i];
        }
    }
    for (int i = 0; i < 100010; i++) {
        if(emax1 < even[i]){
            emax2 = emax1;
            emax1 = even[i];
            evennum = i;
        }
        else if(emax2 < even[i]){
            emax2 = even[i];
        }
    }
    if(oddnum != evennum) ans = n - omax1 - emax1;
    else ans = min(n - omax1 - emax2, n - omax2 - emax1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024