akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define INF 1e9

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

    while(1){
        int n;
        cin>>n;

        if(n==0)break;

        vector<int> a(n);

        for(int i=0;i<n;i++)cin>>a[i];

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

        int ans=INF;

        for(int i=0;i<n-1;i++){
            int d=a[i+1]-a[i];
            ans=min(ans,d);
        }

        cout<<ans<<endl;

    }
    
}


Measured memory_bytes: 3092
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: x * -1, A))
heapq.heapify(A)
for i in range(M):
    heapq.heappush(A, (heapq.heappop(A) + 1) // 2)
print(sum(A) * -1)

Measured memory_bytes: 73068
import java.util.Scanner;
public class Main{
    public static boolean check(int num, int A[], int start){
        if(start == A.length || num <= 0)
            return false;
        else if(A[start] == num)
            return true;
        else
            return (check(num-A[start],A,start+1) || check(num,A,start+1));
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int A[] = new int[n];
        for(int i = 0 ; i < n ; i++)
            A[i] = sc.nextInt();
        int q = sc.nextInt();
        for(int i = 0 ; i < q ; i++){
            int num = sc.nextInt();
            if(check(num,A,0))
                System.out.println("yes");
            else
                System.out.println("no");
        }
    }
}


Measured memory_bytes: 26944
//Night's template
//orzakyrt
#include <bits/stdc++.h>
#define R register
#define LL long long
#ifdef __DEBUG__
	#define Debug (fprintf(stderr,"orzyrt\n"),fflush(stderr))
	#define debug(__a...) (fprintf(stderr,__a),fflush(stderr))
#else
	#define Debug ('orzyrt')
	#define debug(__a...) ('orzyrt')
#endif
inline void Compile(R char *s){
	char com[111];
	sprintf(com,"g++ %s.cpp -lm -o %s",s,s);
	system(com);
}
inline void setfile(R char *s){
	char inname[111],outname[111];
	sprintf(inname,"%s.in",s);
	sprintf(outname,"%s.out",s);
	freopen(inname,"r",stdin);
	freopen(outname,"w",stdout);
}
#ifdef __DEBUG__
	#define setfile(__a) (1)
#endif
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
template<class TT>inline TT Abs(R TT a){return a<0?-a:a;}
template<class TT>inline TT cmin(R TT &a,R TT b){(b<a)&&(a=b);}
template<class TT>inline TT cmax(R TT &a,R TT b){(a<b)&&(a=b);}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
//end template

namespace Night{
	char s[222222];
	int n;
	int main(){
		scanf("%s",s+1);
		n=strlen(s+1);
		if(s[1]=='0' || s[n]=='1')goto failed;
		for(R int i=2;i<n;++i)
			if(s[i]!=s[n-i])goto failed;
		for(R int u=n,v=n-1;v>0;v--){
			printf("%d %d\n",u,v);
			if(s[v]=='1')u=v;
		}
		return 0;
		failed:puts("-1");
		return 0;
	}
}
int main(){
	return Night::main();
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int n,a[394],b[394],c[394];
int dp[394][394];

int main(){
  cin>>n;
  for(int i=1;i<=n;i++)cin>>a[i]>>b[i]>>c[i];
  for(int i=0;i<394;i++)for(int j=0;j<394;j++)dp[i][j]=-1;

  dp[0][0]=0;
  for(int i=1;i<=n;i++){
    for(int j=0;j<=393;j++){      
      dp[i][j]=dp[i-1][j];      
      for(int k=a[i];k<=b[i];k++){
	if(j-k>=0&&dp[i][j-k]>=0)dp[i][j]=max(dp[i][j],dp[i][j-k]+c[i]);
      }
    }
  }

  int q,Q;
  cin>>Q;
  vector<int> ans;
  while(Q--){
    cin>>q;
    ans.push_back(dp[n][q]);
    if(dp[n][q]==-1){
      cout<<-1<<endl;
      return 0;
    }
  }
  for(int i=0;i<ans.size();i++)cout<<ans[i]<<endl;
  return 0;
}

Measured memory_bytes: 1832
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val V, E = sc.nextInt
    val uf = new IUnionFind(V)
    val A = Array.fill(E)(Array.fill(3)(sc.nextInt)).sortBy(x => x(2))
    var ans = 0
    for (bridge <- A) {
      if (!uf.connected(bridge(0), bridge(1))) {
        uf.union(bridge(0), bridge(1))
        ans += bridge(2)
      }
    }
    println(ans)
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}




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

bool pr[100001];
vector<ll> cp;
vector<int> c;
int mx = 1e5;
ll mxx = 1e10;
map<ll, int> fr;
set<ll> vis;

int main() {
	for (int i = 2; i*i <= mx; ++i)if (!pr[i])for (int j = i*i; j <= mx; j += i)pr[j] = true;
	f(i, 2, mx + 1) if (!pr[i]) {
		ll z = (ll)i*i*i;
		if (z <= mxx)cp.push_back(z), c.push_back(i);
		else break;
	}
	int n, an = 0;
	scanf("%d", &n);
	f(i, 0, n) {
		ll t;
		scanf("%lld", &t);
		f(j, 0, cp.size()) {
			if (t == 1)break;
			while (t%cp[j] == 0)t /= cp[j];
		}
		++fr[t];
	}
	if (fr[1])++an;
	fr.erase(1);
	for (map<ll, int>::iterator it = fr.begin(); it != fr.end(); ++it) {
		ll z = it->first;
		if (vis.find(z) != vis.end())continue;
		ll o = 1;
		bool st = false;
		f(i, 0, c.size()) {
			int p = c[i], q = p*p;
			if (z%p == 0) {
				if (z%q == 0)o *= p, z /= q;
				else o *= q, z /= p;
				if (o > mxx) { st = true; break; }
			}
		}
		if (z > 1) {
			ll t = sqrt(z);
			if (t*t == z)o *= t;
			else if (z > mx)st = true;
			else o *= z*z;
			if (o > mxx)st = true;
		}
		if (st) { an += it->second; continue; }
		z = o;
		vis.insert(z);
		map<ll, int>::iterator it1 = fr.find(z);
		int a;
		if (it1 != fr.end())a = it1->second; else a = 0;
		an += max(it->second, a);
	}
	printf("%d", an);
}

Measured memory_bytes: 9344
n = "0" + input() # 文字列として受け取り
N = len(n)
plus = 1
just = 0
for i in range(1,N):
    #前の桁がplusだった場合の最低枚数を計算する
    plus_plus = plus+10-(int(n[i])+1)#この桁も１枚多く払う
    plus_just = plus+10-int(n[i])#この桁はちょうど払う
    #前の桁はちょうど払っていた場合
    just_plus = just+1+int(n[i])#この桁は１枚多く払う
    just_just = just+int(n[i])#この桁もちょうど払う
    
    plus = min(plus_plus,just_plus)
    just = min(just_just,plus_just)

#最後の桁は1枚余分に払う必要がない
print(just)

Measured memory_bytes: 5492
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

char field[100][100];

void move(int h, int w) {
  char c = field[h][w];
  if(c == '.') cout << w << ' ' << h << endl;
  else if(c == '#') cout << "LOOP" << endl;
  else {
    field[h][w] = '#';
    if(c == '<') move(h, w-1);
    else if(c == '>') move(h, w+1);
    else if(c == 'v') move(h+1, w);
    else move(h-1, w);
  }
}

int main() {
  int h, w;

  while(1) {
    cin >> h >> w;
    if(h == 0 && w == 0) break;
  
    REP(i, h) {
      REP(j, w) {
	char c;
	cin >> c;
	field[i][j] = c;
      } 
    }
    move(0, 0);
  }
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
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; }
  
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int n;
  cin >> n;
  cout << n*n*n << endl;
  return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void)
{		
	int h, w;
	
	while (1) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;
		
		for (int i = 1; i <= h; i++) {
			for (int j = 1; j <= w; j++) {
				cout << "#";
			}
			cout << "\n";
		}
		cout << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef string str;
const long long INF = INT64_MAX;

#define REP(i, n) for(ll i=0;i<n;i++)
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define UNIQ(v) ASC(v);erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve() {
    vll v(3);
    for(auto &a:v) cin >> a;
    DESC(v);
    ll bc = v[1] + v[2];
    if(bc % 2 == 0) {
        cout << v[0] - bc / 2 << endl;
    }else {
        cout << v[0] - bc / 2 + 1 << endl;
    }
}

int main() {
    FIO;
    solve();
    return 0;
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int t;
		string s;
		cin >> t >> s;
		if (!t)break;
		int n = s.size(), cnt = 0, cmax = -1;
		vi ans;
		REP(i, (1 << n - 1)) {
			int sum = 0;
			int tmp = 0;
			vi x;
			REP(j, n) {
				tmp *= 10;
				tmp += s[j] - '0';
				if (i & 1 << j) {
					sum += tmp;
					x.push_back(tmp);
					tmp = 0;

				}
			}
			sum += tmp;
			x.push_back(tmp);
			if (sum <= t) {
				if (sum == cmax)cnt++;
				else if (sum > cmax) {
					cnt = 1;
					cmax = sum;
					ans = x;
				}
			}
		}
		if (cmax == -1)cout << "error" << endl;
		else if (cnt > 1)cout << "rejected" << endl;
		else {
			cout << cmax << " ";
			DUMP(ans);
		}
	}
	return 0;
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    ll h, n; cin >> h >> n;
    ll tmp;
    while (n--) {
        cin >> tmp;
        h -= tmp;
    }
    cout << (h <= 0? "Yes": "No") << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

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; }
const ll INF = 1e9;
const long long INFL = 1LL<<60;


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

  int lo = 0;
  int hi = n-1;
  int mid;
  cout << 0 << endl;
  string s_zero;
  cin >> s_zero;
  if (s_zero == "Vacant") return 0;

  string s_lo, s_mid, s_hi;
  s_lo = s_zero;
  rep(i, 19) {
    if (hi - lo == 1) {
      string s;
      cout << hi << endl;
      cin >> s;
      if (s == "Vacant") return 0;
      cout << lo << endl;
      cin >> s;
      if (s == "Vacant") return 0;
    }
    mid = (lo + hi) / 2;
    // cerr << lo << " " << mid << " " << hi << endl;
    cout << mid << endl;
    cin >> s_mid;
    if (s_mid == "Vacant") return 0;
    if ((mid % 2 == lo % 2 && s_mid != s_lo) || (mid % 2 != lo % 2 && s_mid == s_lo)) {
      hi = mid;
      s_hi = s_mid;
    } else {
      lo = mid;
      s_lo = s_mid;
    }
  }

  return 0;
}


Measured memory_bytes: 852
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  auto n = readln.chomp.to!int;
  auto d = readln.chomp.split.to!(int[]);
  d.sort();
  writeln(d[n/2] - d[n/2-1]);
}


Measured memory_bytes: 4420
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a=0,b=0,c=0,d=0;
	while(n--){
		string s;
		cin>>s;
		if(s=="AC")a++;
		else if(s=="WA")b++;
		else if(s=="TLE")c++;
		else d++;
	}
	cout<<"AC x "<<a;
	cout<<"\nWA x "<<b<<"\n";
	cout<<"TLE x "<<c<<"\n";
	cout<<"RE x "<<d;
	return 0;
}
		


Measured memory_bytes: 3588
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <string>
#include <utility>

#define repd(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}

int main(){
	//source
	int n;
	string s;
	cin >> n;
	cin >> s;
	int red=0,blue=0;
	rep(i,n){
		if(s[i]=='R'){
			red++;
		}else{
			blue++;
		}
	}
	if(red>blue){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

int main()
{
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    while (B <= A)
    {
        B *= 2;
        K -= 1;
    }
    while (C <= B)
    {
        C *= 2;
        K -= 1;
    }

    if (K < 0)
    {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int x;
    cin >> x;
    cout << 360 / gcd(x, 360) << "\n";
    
    return 0;
}


Measured memory_bytes: 3644
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        double x = scanner.nextDouble();
        double money = 100;
        int count = 0;
        while(money < x){
            money = Math.floor(money * 1.01);
            count++;
        }
        System.out.println(count);
    }
}



Measured memory_bytes: 37480
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace _gnu_pbds;
#define vb __int128
#define ll long long
#define ld long double
#define full(a) a.begin(),a.end()
#define fr(i,a,b) for(ll i = a ; i < b ; i++)
#define stoink stack<ll>
#define quu queue<ll>
#define quee queue<pair<ll,ll>>
#define vec vector <ll>
#define vg vector<vector<ll> >
#define eg vector<pair<ll,ll>>
#define vgw vector<vector<pair<ll,ll> > >
#define pa pair<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define pre 0.00000000000000000001
#define inf 100000000000000000
#define mod 998244353
#define endl '\n'
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    ll s,n;
        cin >> n >> s;
        vec weight(n+1),val(n+1);
        vec dp(100005,0);
        fr(i,0,n) cin >> weight[i] >> val[i];
        dp[0] = 0;
            fr(i,0,n)
            for(int j = 100000 ; j >= weight[i] ; j--) {
                    dp[j] = max(dp[j],val[i] + dp[j - weight[i]]);
            }
        cout << dp[s];
	return 0;
}

Measured memory_bytes: 3964
// -*- coding:utf-8-unix -*-

use proconio::input;
use proconio::marker::{Bytes, Chars};
use num_integer;

fn main() {
    input! {
        n: i64,
    }


    let mut sum = 0;
    for i in 1..=n {
        for j in 1..=n {
            for k in 1..=n {
                let temp =  num::integer::gcd(j,k);
                let temp1 =  num::integer::gcd(temp, i);
                sum = sum + temp1;
            }
            
        }
        
    }

    println!("{}", sum);


    // let mut sum = 0;
    // for i in 1..=n {
    //     if i % 3 != 0 && i % 5 !=0 && i % 15 != 0{
    //         sum = sum + i
    //     }
    // }
    
    // println!("{}",sum)


    // let mut yes = false;
    // for s in  n {
    //     if s == '7' {
    //         yes = true;
    //     }
    // }
    // if yes {
    //     println!("Yes" )
    // }else{
    //     println!("No")
    // }


}


Measured memory_bytes: 2116
<?php

class BubbleSort
{
    public function rearrangeNumbers()
    {
        $numbers = $this->getInput();
        $count = 0;

        for ($i = 0; $i < count($numbers) - 1; $i++) {
            for ($j = count($numbers) - 1; $j > $i; $j--) {
                if ($numbers[$j] < $numbers[$j - 1]) {
                    list($numbers[$j], $numbers[$j - 1]) = [$numbers[$j - 1], $numbers[$j]];
                    $count++;
                }

            }
        }

        echo implode(" ", $numbers) . PHP_EOL;
        echo $count . PHP_EOL;
    }
    
    public function getInput()
    {
        $input_number = trim(fgets(STDIN));

        while (True) {
            $input_numbers = explode(" ", trim(fgets(STDIN)));
            if (count($input_numbers) == $input_number) {
                break;
            }
        }
        
        return $input_numbers;
    }
}

$bubble_sort = new BubbleSort();
$bubble_sort->rearrangeNumbers();



Measured memory_bytes: 9388
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>

using namespace std;

typedef long long ll;

int main() {
    int h, w;   cin >> h >> w;
    string *s = new string[h];
    int black = 0;
    for (int i = 0; i < h; i++) {
        cin >> s[i];
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#')
                black++;
        }
    }

    int dh[] = {1, 0, -1, 0};
    int dw[] = {0, 1, 0, -1};
    vector<vector<int> > d(h, vector<int>(w, -1));

    typedef pair<int,int> P;
    queue<P> que;

    d[0][0] = 0;
    que.push(P(0, 0));

    while (!que.empty()) {
        P u = que.front();
        que.pop();

        for (int i = 0; i < 4; i++) {
            int nh = u.first + dh[i], nw = u.second + dw[i];

            if (nh < 0 || h <= nh || nw < 0 || w <= nw || d[nh][nw] != -1 || s[nh][nw] == '#')
                continue;
            
            d[nh][nw] = d[u.first][u.second] + 1;

            que.push(P(nh, nw));
        }
    }

    if (d[h-1][w-1] == -1)
        cout << -1 << endl;
    else 
        cout << h*w - black - d[h-1][w-1]-1 << endl;

    return 0;
}

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

using namespace std;

#define int long long

int p[20];

int bt(int num,int pos,int rem) {
    if (pos == num / 2)
        return  rem == 0;
    int rrr = -(rem % 10);
    if (rrr < 0)  rrr += 10;
    int ans  = bt(num,pos + 1,(rem - rrr * p[num - 2 * pos - 1]) / 10) * (10 - rrr - (pos == 0));
    if (rrr > 0)
        rrr -= 10,
        ans += bt(num,pos + 1,(rem - rrr * p[num - 2 * pos - 1]) / 10) * (10 + rrr - (pos == 0));
    return  ans;
}

signed main()   {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int dif;    cin >> dif;
    int ans = 0;

    for(int i = 1 ; i <= 18 ; ++i)
        p[i] = p[i - 1] * 10 + 9,
        ans += bt(i,0,dif) * (i & 1 ? 10 : 1);

    cout << ans << endl;
}

Measured memory_bytes: 256
s=input()
q=int(input())
flag=1
a=""
b=""
for _ in range(q):
    query=input().split()
    if query[0]=="1":
        flag*=-1
    else:
        if flag==1:
            if query[1]=="1":
                a+=query[2]
            else:
                b+=query[2]
        else:
            if query[1]=="1":
                b+=query[2]
            else:
                a+=query[2]
if flag==1:
    print(a[::-1]+s+b)
else:
    print(b[::-1]+s[::-1]+a)

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(void){
    int n,mw; cin >> n >> mw;
    int v[n],w[n];
    rep(i,0,n){
        cin >> v[i] >> w[i];
    }
    int dp[n+1][mw+1];
    rep(i,0,mw+1){
        dp[0][i] = 0;
    }
    rep(i,0,n){
        rep(j,0,mw+1){
            if(j-w[i] >= 0){
                dp[i+1][j] = max(dp[i][j], dp[i+1][j-w[i]] + v[i]);
            }else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    // rep(i,0,n+1){
    //     rep(j,0,mw+1){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << "\n";
    // }
    cout <<dp[n][mw] << "\n";
}


Measured memory_bytes: 7044
import numpy as np
n = int(input())
a_ls = list(map(int, input().split()))

# -1, 0, 右端も用意
updown_ls = [0] * (10**5 + 3)

for i in range(n):
    left = a_ls[i] 
    right = a_ls[i] + 3
    updown_ls[left] += 1
    updown_ls[right] -= 1

updown_ls.pop()
num_ls = list(np.cumsum(updown_ls))
print(max(num_ls))

Measured memory_bytes: 25068
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int par[100010], sz[100010], ran[100010] = { };
void init(int n) {
  rep(i,n)
  {
    par[i] = i;
    sz[i] = 1;
  }
}
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return;
  if (ran[x] < ran[y])
    swap(x, y);
  if (ran[x] == ran[y])
    ran[x]++;
  par[y] = x;
  sz[x] += sz[y];
}
bool same(int x, int y) {
  return find(x) == find(y);
}
int size(int x) {
  return sz[find(x)];
}
int main() {
  ll n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  ll ans[m];
  rep(i,m)
    scanf("%d%d", &p[i].first, &p[i].second);
  init(n + 2);
  ll now = n * (n - 1) / 2;
  ans[m - 1] = now;
  for (int i = m - 1; i > 0; i--) {
    if (!same(p[i].first, p[i].second)) {
      now -= size(p[i].first) * size(p[i].second);
      unite(p[i].first, p[i].second);
    }
    ans[i - 1] = now;
  }
  rep(i,m)
    cout << ans[i] << endl;
}


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

int func(int a) {
  int ans = 0;
  for (int i = a + 1; i <= 2*a; i++) {
    bool flag = true;
    for (int j = 2; j*j <= i; j++) {
      if (i % j == 0) {
        flag = false;
      }
    }
    if (flag) {
      ans++;
    }
  }
  return ans;
}

int main() {
  int n;
  while (cin >> n && n > 0) {
    int ans = func(n);
    cout << ans << endl;
  }
  return 0;
}


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

const int mxn = 2003;
const long long mod = 1e9 + 7;

long long c[mxn][mxn];

int main() {

    int n, k;

    cin >> n >> k;

    c[0][0] = c[1][1] = c[1][0] = 1;
    for (int i = 2; i <= n; i++) {
        c[i][0] = c[i][i] = 1;
        for (int j = 1; j < i && j <= k; j++) {
            c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
        }
    }
    for (int i = 1; i <= k; i++) {
        cout << (c[k - 1][i - 1] * c[n - k + 1][i]) % mod << endl;
    }

    return 0;
}


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

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

int height[N];

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

int dp[N];

dp[0] = 0; // 初期位置なのでもちろん0

//2番目の位置は初期位置からの移動しかありえないので
dp[1] = dp[0] + abs(height[1] - height[0]);

//3番目以降は1つ前と2つ前の2パターンを計算して小さい方を選択
for (int i=2; i<N; i++){
    //１つ前から移動した場合のコストを求める
    int jumpFrom_1 = dp[i-1] + abs(height[i-1] - height[i]);
    //２つ前から移動した場合のコストを求める
    int jumpFrom_2 = dp[i-2] + abs(height[i-2] - height[i]);
    dp[i] = min(jumpFrom_1, jumpFrom_2);
}

cout << dp[N-1] << endl;
}


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

using namespace std;

const int NMAX = 1e5;

int N, K;
int h[NMAX + 5], dp[NMAX + 5];

int main()
{
    cin >> N >> K;
    for(int i = 1; i <= N; i++)
        cin >> h[i];

    dp[1] = 0;
    for(int i = 2; i <= N; i++)
    {
        dp[i] = 1 << 30;
        for(int j = 1; j <= K && j < i; j++)
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
    
    cout << dp[N];

    exit(0);
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
  int n, m;
  cin >> n >> m;
  int ans = 0;
//  if(n >= 2) {
    ans += n * (n -1) / 2;
//  }
//  if(m >= 2) {
    ans += m * (m - 1) /2;
//  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    string s; cin >> s;
    int a, b;
    a = (s[0] - '0')*10 + (s[1] - '0');
    b = (s[2] - '0')*10 + (s[3] - '0');
    if(a <= 12 and a > 0 and b <= 12 and b > 0) cout << "AMBIGUOUS" << endl;
    else if(b <= 12 and b > 0) cout << "YYMM" << endl;
    else if(a <= 12 and a > 0) cout << "MMYY" << endl;
    else cout << "NA" << endl;
}

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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cerr << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define debug(...) CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) (__VA_ARGS__)

using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1e14;

int n, a, b, c;

void cl(int k, vector<int> &L) {
  L.resize(n);
  rep(i, n) {
    L[i] = k % 4;
    k /= 4;
  }
}

void Main() {
  cin >> n >> a >> b >> c;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  int num = 1;
  rep(_, n) num *= 4;
  int ans = 1000000;
  vector<int> M;
  rep(k, num) {
    cl(k, M);
    int x, y, z;
    x = y = z = 0;
    int score = 0;
    rep(i, n) {
      if (M[i] == 0) {
        if (x > 0) score += 10;
        x += l[i];
      } else if (M[i] == 1) {
        if (y > 0) score += 10;
        y += l[i];
      } else if (M[i] == 2) {
        if (z > 0) score += 10;
        z += l[i];
      }
    }
    if (x == 0 || y == 0 || z == 0) continue;
    score += abs(a - x) + abs(b - y) + abs(c - z);
    ans = min(score, ans);
  }
  cout << ans << endl;
}

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


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

int R, G, B, N;
int res;

int main()
{
    scanf("%d %d %d %d", &R, &G, &B, &N);
    for (int r = 0; r <= N; r++)
        for (int g = 0; g <= N; g++) {
            int b = N - r * R - g * G;
            if (b >= 0 && b % B == 0) res++;
        }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int a,b,c,d,e,f;
    scanf("%d %d",&a,&b);
    c=a+b;
    d=a-b;
    e=a*b;
    if(c<d){
        f=c;
        c=d;
        d=f;
    }
    if(d<e){
        f=d;
        d=e;
        e=f;
    }
    if(c<d){
        f=c;
        c=d;
        d=f;
    }
    printf("%d",c);
}

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

using namespace std;

int main(){
    int n, m;
    while(cin >> n >> m && n && m){
        int ans = 0;
        for(int i = 0; i < n; i++){
            int a;
            cin >> a;
            ans += min(a, m / n);
        }
        cout << ans << "\n"; 
    }
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n,m,x;
  cin >> n >> m >> x;
  int a;
  vector<int> gate(n+1, 0);
  REP(i,m) { cin >> a; gate[a]=1; }

  int left=0,right=0;
  REP(i,x) if (gate[x-i]) left++;
  REP(i,n-x) if (gate[x+i]) right++;
  COUT(min(left,right));
  return 0;
}


Measured memory_bytes: 256
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        abc121cEnergyDrinkCollectorSolve(n,m,a,b);
        sc.close();
    }

    public static void abc121cEnergyDrinkCollectorSolve(int n, int m, int[] a, int[] b) {
        long sum = 0;
        int numcount = 0;
        int ite = 0;
        boolean bool = true;
        Integer[] id = new Integer[n];
        for (int i = 0; i < n; i++) {
            id[i] = i;
        }
        Arrays.setAll(id, i -> i);
        Arrays.sort(id, Comparator.comparingInt(i -> a[i]));
        while(bool){
            if (numcount + b[id[ite]] < m) {
                sum += (long)b[id[ite]] * (long)a[id[ite]];
                numcount += b[id[ite]];
            } else {
                sum += (long)(m-numcount) * (long)a[id[ite]];
                bool = false;
            }
            ite++;
        }
        System.out.println(sum);
    }
}





Measured memory_bytes: 65512
x, n = map(int, input().split())
p = set(list(map(int, input().split())))
a = set(list(range(102)))
a = list(a - p)
a.sort()

tmp = 10 ** 10
for i in a:
    if tmp > abs(x - i):
        tmp = abs(x - i)
        ans = i
print(ans)

Measured memory_bytes: 9192
//#define LOCAL 
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <list>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
#ifdef LOCAL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
	
	int n;
	cin >> n;
	cout << (1 + n) * n / 2;	
		
	return 0;
}

Measured memory_bytes: 256
s = list(map(str, input().split()))
s = s[0]
n = len(s)

ans = 0
now = 0
fin = '.'
fin2 = '.'

while(True):

    if(s[now]!=fin or now == n-1):
        ans += 1
        fin2 = fin
        fin = s[now]
        now += 1
        last = 0
    else:
        ans += 1
        fin2 = fin
        fin = '.'
        now += 2
        last = 1
    
    #print(now)
    #print(fin2,fin)
    if(now >= n):
        break


if(fin == fin2):
    ans -= 1

print(ans)

Measured memory_bytes: 41180
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [1001001001001001001] * n
dp[0] = 0
for i in range(n):
    for j in range(i + 1, min(i + k + 1, n)):
        dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]))
print(dp[n-1])

Measured memory_bytes: 84776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;



struct edge{
    ll to;
    ll cost;
};

void dijkstra(ll s, vector<vector<edge>> G, vector<ll> &d){
    //first : 最短距離、second : 頂点番号
    priority_queue< llll, vector<llll>, greater<llll>> que;
    fill(ALL(d), INF);

    d[s] = 0;
    que.push(make_pair(0, s));

    while(!que.empty()){
        llll q = que.top(); que.pop();
        ll v = q.second;

        if(q.first > d[v]) continue;

        for (edge e : G[v]) {
            if(q.first + e.cost >= d[e.to]) continue;
            d[e.to] = q.first + e.cost;
            que.push(make_pair(d[e.to], e.to));
        }
    }
}

int main(){
    ll n, m, s, t; cin >> n >> m >> s >> t;
    vector<vector<edge>> Gy(n+1);
    vector<vector<edge>> Gs(n+1);
    vector<ll> ds(n+1);
    vector<ll> dt(n+1);



    ll tmp1, tmp2;
    edge tmpy, tmps;
    for (int i = 0; i < m; i++) {
        cin >> tmp1 >> tmp2 >> tmpy.cost >> tmps.cost;
        tmpy.to = tmp2;
        tmps.to = tmp2;
        Gy[tmp1].push_back(tmpy);
        Gs[tmp1].push_back(tmps);
        tmpy.to = tmp1;
        tmps.to = tmp1;
        Gy[tmp2].push_back(tmpy);
        Gs[tmp2].push_back(tmps);
    }

    dijkstra(s, Gy, ds);
    dijkstra(t, Gs, dt);

    vector<ll> ans(n);
    ans[n-1] = ds[n] + dt[n];
    for (ll i = n-2; i >= 0; i--) {
        ans[i] = min(ans[i+1], ds[i+1] + dt[i+1]);
    }

    ll moto = 1000000000000000;
    for (ll i = 0; i < n; i++) {
        printf("%lld\n", moto - ans[i]);
    }


}


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A*10+B+C>=A+C+B*10 && A*10+B+C >= C*10 + A+B ){
    cout << A*10 + B + C;
  }
  else{
    if(A+C+B*10 >C*10+A+B)
  cout << A+ C+B*10;
  else
    cout << A+B+C*10;
  }
return 0;
}


Measured memory_bytes: 256
import sys


def distance(p1, p2):
    x1, y1 = p1
    x2, y2 = p2
    return abs(x2 - x1) + abs(y2 - y1)


H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())

P = [None] * (H * W + 1)
P[0] = (0, 0)
for i in range(H):
    for j in range(W):
        P[A[i][j]] = (i, j)

S = [0] * (H * W + 1)
for i in range(1, H * W + 1):
    pi = max(0, i - D)
    S[i] = S[pi] + distance(P[pi], P[i])

ans = []
for q in sys.stdin.readlines():
    L, R = map(int, q.split())
    ans.append(S[R] - S[L])

print(*ans, sep='\n')


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

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        int outCount=0, base=0, point=0;
        while(outCount < 3){
            char event[8]={0};
            scanf("%s",event);
            if(event[1] == 'I'){
                base <<= 1;
                base |= 1;
                if(base & 8){
                    point++;
                    base ^= 8;
                }
            }else if(event[0] == 'H'){
                int runnerCnt=1;
                while(base > 0){
                    if(base & 1)runnerCnt++;
                    base >>= 1;
                }
                point += runnerCnt;
            }else{
                outCount++;
            }
        }
        printf("%d\n",point);
    }
    return 0;
}

Measured memory_bytes: 1188
import java.util.*;
import java.io.*;

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    
        int n = Integer.parseInt(br.readLine());
        
        if(n % 1000 != 0){
            out.println(1000 - (n % 1000));
        }else{
            out.println(0);
        }
        
        out.close();
        
    }
}

Measured memory_bytes: 32800
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

int main()
{ 
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++){
        if(i==0){a[i]=0;}
        else if(i==n-1){a[i]=1;}
        else{a[i]=0;}
    }
    int l[n];
    for(int i=0;i<n;i++){l[i]=0;}

    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x=n-x;
        if(l[x]==1){
            if(a[x]!=y){
                cout<<-1<<endl;
                return 0;
            }
        }
        else{l[x]=1;a[x]=y;}
    }
    if(n>=2&&a[n-1]==0){cout<<-1<<endl;return 0;}
    for(int i=n-1;i>=0;i--){cout<<a[i];}
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define foi(i,a,n) for(int i=a;i<n;i++)
#define el "\n"
const int INF = 2e9+5;
void solve(){
 	int n,k;cin>>n>>k;
  	vector<int> h(n), c(n,INF);rep(i,n) cin>>h[i];
  	c[0]=0;
  	foi(i,1,n)foi(j,max(0,i-k),i) c[i]=min(c[i],c[j]+abs(h[j]-h[i]));
  	cout<<c[n-1]<<" ";
}

int main(){
  solve();
  return 0;
}

Measured memory_bytes: 3928
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, a[11], res;

signed main() {
	cin >> n;
	rep(i,n) cin >> a[i];
	sort(a, a+n);
	rep(i,n-1) res += a[i];
	res += a[n-1]/2;
	cout << res << endl;
}

Measured memory_bytes: 256
h, w, a, b = map(int, input().split())
ans = [0] * h
for i in range(b):
    ans[i] = '1'*a + '0'*(w-a)
for i in range(b, h):
    ans[i] = '0'*a + '1'*(w-a)

for i in range(h):
    print(ans[i])

Measured memory_bytes: 4980
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)(1e9))
#define pi (1.0*acos(-1))
#define M ((int)(258280327))
#define NN ((ll)(305))
#define N ((ll)(2e5+7))
#define eps 0
#define log 20


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;


typedef tree < ll,  null_type,  less < ll >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;

vector < int > v[N];

pair < int,int > dfs(int n, int par)
{
    //cout<<n<<" "<<par<<endl;
    pair < int,int > p;
    p.first = n;
    p.second = 0;
    for(int i = 0; i<v[n].size(); i++){
        if(v[n][i]!=par){
            pair < int,int > tmp  = dfs(v[n][i],n);
            if(tmp.second+1>p.second){
                p = tmp;
                p.second++;
            }
        }
    }

    //cout<<"end\n";

    //p.second++;
    return p;
}

int main()
{
    int n, m;
    scanf("%d",&n);
    for(int i = 1; i<n; i++){
        int a,b;
        scanf("%d %d",&a,&b);
        v[b].push_back(a);
        v[a].push_back(b);
    }
    //cout<<"sad\n";

    pair < int,int > p = dfs(1,0);
    //cout<<p.first<<endl;

    p = dfs(p.first,0);

    int a = p.second + 1;
    //cout<<a<<endl;
    if(a%3<2) printf("First\n");
    else printf("Second\n");
    return 0;


}


Measured memory_bytes: 26752
X,A,B=list(map(int,input().split(" ")))

if B<=A: # 賞味期限内の場合
    print("delicious")
elif (B-A)<=X: # 賞味期限は過ぎたが、お腹は壊さない場合
    print("safe")
else: # お腹を壊す場合
    print("dangerous")

Measured memory_bytes: 2940
n,*t=map(int,open(0).read().split());e=[[]for _ in[0]*n];q=[0];f=[0]+[-1]*~-n
for v,w,c in zip(t[::3],t[1::3],t[2::3]):e[v-1]+=(w-1,c),;e[w-1]+=(v-1,c),
while q:
 v=q.pop()
 for w,c in e[v]:
  if f[w]<0:f[w]=(c+f[v])%2;q+=w,
print(*f)

Measured memory_bytes: 49896
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

typedef pair<long long, long long> P;
int main(){
    int n;
    cin>>n;
    vector<int> h;
    rep(i,n){
        int hu;
        cin>>hu;
        h.push_back(hu);
    }
    bool flag=1;
    int ans;
    while(flag){
        int mx=0;
        rep(i,n){
            mx=max(mx,h[i]);
        }
        if(mx==0){
            flag=0;
            break;
        }
        rep(i,n){
            if(h[i]==0){
                continue;
            }
            for(int j=i; j<n; j++){
                if(h[j]==0){
                    break;
                }
                h[j]--;
            }

            break;
        }
        ans++;

    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9+7
#define LINF (long long)4e18


int main(){
    long long A,B,C,K;
    cin >> A >> B >> C >> K;
    long long ans;
    if(K % 2 == 1)ans = B-A;
    else ans = A-B;
    if(abs(ans) > (long long)1e18) cout << "Unfair" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n;
void pai(int a[],int &l)
{
	int o=a[0];
	for(int p=0;p<n;p++)
	{
		if(a[p]>=o) 
		{
			o=a[p];
			l=p;}
	}
}

int main()
{

	cin>>n;
	int a[100],k=0,b[100];
	
	for(int i=1;i<=n;i++)
	{
		int j=i; int m=0;
		while(j%2==0)
		{j=j/2;m++;}
		a[k]=m;
		b[k]=i;k++;
	}
	int l;
	pai(a,l);
	cout<<b[l];
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
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()
{
	int n; cin >> n;
	string s; cin >> s;
	int red = 0, blue = 0;
	rep(i, n)
	{
		if (s[i] == 'R')red++;
		else blue++;
	}
	if (red > blue)co("Yes");
	else co("No");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int n, i;
	long long int sum = 0;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		if (i % 3 != 0 && i % 5 != 0) sum += i;
	}
	printf("%lld", sum);
}

Measured memory_bytes: 1724
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int N, K;
	cin >> N >> K;
	if (N % 2 == 0) {
		if (N / 2 >= K)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	else {
		if (N / 2 + 1 >= K)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}


Measured memory_bytes: 256