akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
using namespace boost::multiprecision;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define mll map<ll,ll>
#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 all(c) c.begin(),c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a),greater<型>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define isu isupper
#define isl islower
#define lb(a,k) lower_bound(all(a),k)
#define ub(a,k) upper_bound(all(a),k)
#define bs(a,k) binary_search(all(a),k)
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

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

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

int main() {
    ll X;
    cin >> X;

    int ans = 0;
    if (X >= 400 && X <= 599) ans = 8;
    if (X >= 600 && X <= 799) ans = 7;
    if (X >= 800 && X <= 999) ans = 6;
    if (X >= 1000 && X <= 1199) ans = 5;
    if (X >= 1200 && X <= 1399) ans = 4;
    if (X >= 1400 && X <= 1599) ans = 3;
    if (X >= 1600 && X <= 1799) ans = 2;
    if (X >= 1800 && X <= 1999) ans = 1;

    cout << ans << endl;
}


Measured memory_bytes: 3632
f n ('2':s) i =0:(f n s i)
f 1 _ i       =[i]
f n s i       =if s!!0==s!!1 then(f(n-1)(tail s)(i+1))else(i:(f(n-1)(tail s)1))
g n k t s i a |n<2       =max i a
              |otherwise =g (n-2) k (drop 2 t) (drop 2 s) (max i a) (a-(sum(take 2 s))+(sum(take 2 t)))
main=do
 [n,k]<-map read.words<$>getLine
 s<-(\x->f n x 1).(\x->if x!!0=='1' then x else ('2':x))<$>getLine
 print(g ((length s)-2*k) (2*k+1) (drop(2*k+1)s) s 0 (sum(take(2*k+1)s)))

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

int main() {
	int n, l;
	cin >> n >> l;
	vector<string> s(n);
	rep(i, n) cin >> s[i];
	sort(all(s));
	rep(i, n) cout << s[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
a = list(map(int, input().split()))
a.sort()
diff1 = a[1] - a[0]
diff2 = a[2] - a[1]
diff3 = a[2] - a[0]
if diff1 % 2 == 0:
    if diff3 % 2 == 0:
        print((diff3 + diff2)//2)
    else:
        print(diff3//2 + diff2//2 + 1)
else:
    if diff3 % 2 == 0:
        print(diff3//2 + diff2//2 + 2)
    else:
        print(diff3//2 + diff2//2 + 2)


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;


inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

i64 dp[310][310];

void solve() {
	int n, k;
	cin >> n >> k;
	vi64 h(n + 1);
	reps(i, n) cin >> h[i];

	rep(i, 310) rep(j, 310) dp[i][j] = 1e18;
	dp[0][0] = 0;

	reps(i, n) reps(j, n) {
		i64 mi = 1e18;
		rep(l, i) {
			amin(mi, dp[l][j - 1] + max(h[i] - h[l], 0ll));
		}
		dp[i][j] = mi;
	}

	i64 ans = 1e18;
	repc(i, n) amin(ans, dp[i][n - k]);
	cout << ans << endl;
}

Measured memory_bytes: 4368
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    K, A, B = map(int, read().split())
    for i in range(A, B +1):
        if i % K == 0:
            print('OK')
            break
    else:
        print('NG')
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
#include <iostream>

using namespace std;

void solve()
{
	int d;
	while(cin >> d)
	{
		int sum = 0;
		for(int i = d; i < 600; i += d)
		{
			sum += d * i * i;
		}
		cout << sum << endl;
	}
}

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

Measured memory_bytes: 1160
N , M = (map(int , input().split()))
A = list(map(int , input().split()))
s = sum(A)
tou = (1/(4*M))*s
count = 0
for i in A:
    if i < tou:
        continue
    else:
        count += 1
if count >= M:
    print('Yes')
else:
    print('No')

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
  string s,t;
  int ans=-1;
  int cnt=0;
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.rbegin(),t.rend());
  //cout<<t<<endl;
  if(s.size()<t.size()){
    r(i,s.size()){
      if(s.at(i)==t.at(i))cnt++;
    }
    if(cnt==s.size())ans=1;
  }

  int ans2=-1;
  int num=min(s.size(),t.size());
  r(i,num){
    if(s.at(i)<t.at(i)){ans2=1;break;}
  }
  

  if(ans2==1 || ans==1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;


return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,q) for(int i = 0; q > i; i++)
#define repp(i,o,q) for(int i = o; q > i; i++)
int main(){
  int N;cin>>N;
  int mina=10000,minb=10000,minc=10000;
  int a[N],b[N],c[N];
  int dp[N][3];
  rep(i,N){
    cin >> a[i] >> b[i] >> c[i];
  }
  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];
  repp(i,1,N){
    dp[i][0] = max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
    dp[i][1] = max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
    dp[i][2] = max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
  }
  cout << max(dp[N-1][0],max(dp[N-1][1],dp[N-1][2])) << endl;
}

Measured memory_bytes: 2560
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		bool[] ac = new bool[N];
		int[] pena = new int[N];
		for(int i=0;i<M;i++){
			if(S[i] == "AC"){
				ac[P[i]] = true;
				continue;
			} else {
				if(!ac[P[i]]){
					pena[P[i]]++;
				}
			}
		}
		
		int accnt = 0;
		for(int i=0;i<N;i++) if(ac[i]) accnt++;
		int wacnt = 0;
		for(int i=0;i<N;i++) if(ac[i]) wacnt += pena[i];
		Console.WriteLine("{0} {1}",accnt, wacnt);
		
		
	}
	int N,M;
	int[] P;
	String[] S;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
		P = new int[M];
		S = new String[M];
		for(int i=0;i<M;i++){
			var ss = rsa();
			P[i] = int.Parse(ss[0]) - 1;
			S[i] = ss[1];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 23880
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>'50000000'},'ruby',$0)
def f(v,c)
	s=m=H[v].size==1?A[v-1]:0
	H[v].any?{|e|
		e==c&&next
		s+=n=f(e,v)
		m=[m,n].max
		n<0		
	}||s<(x=2*A[v-1]-s)||x<2*m-s ?-1:x
end
G=->{gets.split.map &:to_i}
n,_=G[]
A=G[]
H=Hash.new{|h,k|h[k]=[]}
(n-1).times{x,y=G[];H[x]<<y;H[y]<<x}
puts f(1,0)==0?:YES: :NO

Measured memory_bytes: 198968
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;


int main(){
    string s;
    cin >> s;
    ll ans=0;
    for(ll i=0;i<4;i++){
        if(s[i]=='+')ans++;
        else ans--;
    ;}
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
using namespace std;

int main(void) {
	int count = 1;
	long long int mini, sum;
	long long int q, h, s, d;
	long long int n;
	cin >> q >> h >> s >> d;
	cin >> n;
	if (4 * q > h * 2) {
		count = 2;
		mini = h * 2;
	}
	else {
		count = 1;
		mini = q * 4;
	}
	if (mini > s) {
		count = 3;
		mini = s;
	}
	if (mini * 2 > d) {
		sum = (n / 2)*d + (n % 2)*mini;
		cout << sum << endl;
	}
	else {
		sum = n*mini;
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	scan_init()
	N := scanInt()
	K := scanInt()
	p := make([]int,N)
	// memo := make(map[int]int,N)
	for i:= 0; i<N; i++ {
		p[i] = scanInt()
	}
	sum := 0
	sort.Ints(p)
	// fmt.Println(p)
	for i:= 0; i<K; i++ {
		sum += p[i]
	}
	fmt.Println(sum)
}
var sc = bufio.NewScanner(os.Stdin)
func scan_init () {
	sc.Split(bufio.ScanWords)
}
func scanInt () int{
	sc.Scan()
	i,_ := strconv.Atoi(sc.Text())
	return i
}
//func scan () string{
//  sc.Scan()
//	return sc.Text()
//}

Measured memory_bytes: 1780
#include<iostream>
#include<bits/stdc++.h>
#define MAX_N 100000
int L[MAX_N],R[MAX_N];
int partition(int * A,int len);
void merge(int *A,int l,int mid,int r);
int main(void){
	int A[MAX_N],n,i,f;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",A+i);
	}
	f=partition(A,n);
	for(i=0;i<n;i++){
		if(i==f) printf("%s[%d]",i==0?"":" ",A[i]);
		else printf("%s%d",i==0?"":" ",A[i]);
	}
	puts("");
	return 0;
	
} 
int partition(int * A,int len){
	int i=-1,j,temp; 			//双指针
	 
	for(j=0;j<len-1;j++){
		if(A[j]<=A[len-1]) {
			i++;
			temp=A[i];
			A[i]=A[j];
			A[j]=temp;
		}
	}
	temp=A[i+1];
	A[i+1]=A[len-1];
	A[len-1]=temp; 
	return i+1;
}


Measured memory_bytes: 3484
def f(s):
    if s[0] == s[1] == s[2] == 'R':
        print(3)
    elif s[0] == s[1] == s[2] == 'S':
        print(0)
    elif (s[0] == s[1] == 'R') or (s[1] == s[2] == 'R'):
        print(2)
    elif (s[0] == s[2] == 'R'):
        print(1)
    else:
        print(1)

s = input()
f(s)


Measured memory_bytes: 9068
#include <iostream>
#include <algorithm>
#include <iomanip>
int p[200005], n;
long long ans = 0;
int main() {
	std::cin >> n;
	for (int i = 0; i < n << 1; i++) std::cin >> p[i];
	std::sort(p, p + n * 2);
	for (int i = 0; i < n << 1; i++) ans += 1LL * i * p[i];
	std::cout << std::fixed << std::setprecision(10) << double(ans) / (2 * n - 1) << std::endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i ,n){
    cin >> a[i];
  }
  rep(i, n-1){
    a[i+1]+=a[i];
  }
  ll now=0, num=0;
  rep(i, n){
    if(i%2==0 && a[i]+now<=0){
      num+=1-(a[i]+now);
      now+=1-(a[i]+now);
    }
    if(i%2==1 && a[i]+now>=0){
      num+=(a[i]+now)+1;
      now-=(a[i]+now)+1;
    }
  }
  ll now2=0, num2=0;
  rep(i, n){
    if(i%2==1 && a[i]+now2<=0){
      num2+=1-(a[i]+now2);
      now2+=1-(a[i]+now2);
    }
    if(i%2==0 && a[i]+now2>=0){
      num2+=(a[i]+now2)+1;
      now2-=(a[i]+now2)+1;
    }
  }
  ll ans=min(num, num2);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4056
n,m=map(int,input().split())
x=[2,5,5,4,5,6,3,7,6]
a=[]
for i in map(int,input().split()):
    a.append([i,x[i-1]])
a.sort(reverse=True)
dp=[0]*(n+1)
for i in range(m):
    for j in range(n+1):
        if j==0 or dp[j]!=0:
            if j+a[i][1]<=n:
                dp[j+a[i][1]]=max(dp[j+a[i][1]],dp[j]*10+a[i][0])
print(dp[n])

Measured memory_bytes: 16492
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define int long long
#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;

inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,BufferSize,stdin);
        tail=(head=buffer)+l;
    }
    return *head++;
}
inline int exread() {
    int x=0,f=1;char c=Getchar();
    for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
    return x*f;
}

inline int read(){
	int sum=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
	return f*sum;
}


const int N=200005;
struct node{int pre,nxt,to2,sp2,to1,sp1;}a[N];
struct ques{int l,r,ans;}q[N];
int n,m,L,p[N];
int bl[N],gap;

inline int work2(int l,int r){
	int ans=0;
	while(bl[l]!=bl[r]&&bl[l]!=bl[n]&&l<r){
		ans+=a[l].sp2,l=a[l].to2;
		ans++;l=a[l].nxt;
	}
	while(l<r) ans++,l=a[l].nxt;
	return ans;
}

inline int work1(int l,int r){
	int ans=0;
	while(bl[l]!=bl[r]&&bl[l]!=bl[1]&&l>r){
		ans+=a[l].sp1,l=a[l].to1;
		ans++;l=a[l].pre;
	}
	while(l>r) {ans++,l=a[l].pre;}
	return ans;
}

signed main(){
//	freopen("test.in","r",stdin);
//	freopen("B.out","w",stdout);
	n=read();gap=sqrt(n);
	for(int i=1;i<=n;i++) p[i]=read();
	for(int i=1;i<=n;i++) bl[i]=(i-1)/gap+1;
	L=read();m=read();
	for(int i=1;i<=m;i++) q[i].l=read(),q[i].r=read();
	for(int i=1;i<=n;i++){
		int k=p[i]+L;
		k=upper_bound(p+1,p+n+1,k)-p-1;
		a[i].nxt=k;
		a[i].pre=lower_bound(p+1,p+n+1,p[i]-L)-p;
	}
	for(int i=1;i<=n;i++){
		int p=i;
		while(bl[a[p].nxt]==bl[i]&&bl[p]!=bl[n]) p=a[p].nxt,a[i].sp2++;
		a[i].to2=p;
		p=i;
		while(bl[a[p].pre]==bl[i]&&bl[p]!=bl[1]) p=a[p].pre,a[i].sp1++;
		a[i].to1=p;
	}
	for(int i=1;i<=m;i++){
		if(q[i].l<q[i].r) q[i].ans=work2(q[i].l,q[i].r);
		else q[i].ans=work1(q[i].l,q[i].r);
	}
	for(int i=1;i<=m;i++) printf("%lld\n",q[i].ans);
	return 0;
}


Measured memory_bytes: 14336
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = int.Parse(Console.ReadLine().Replace(" ",string.Empty));
            if (r % 4 == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {
	static class Node {
		int value;
		Node prev;
		Node next;
		
		public Node(int value, Node prev, Node next) {
			this.value = value;
			this.prev = prev;
			this.next = next;
		}
	}
	
	static class MyList {
		Node start;
		Node end;
		Node cursor;
		
		public void insert(int num) {
			Node tmp = new Node(num, cursor.prev, cursor);
			cursor.prev.next = tmp;
			cursor.prev = tmp;
			cursor = tmp;
		}
		
		public void move (int d) {
			if (d < 0) {
				d *= -1;
				for (int i = 0; i < d; i++) {
					cursor = cursor.prev;
				}
			} else {
				for (int i = 0; i < d; i++) {
					cursor = cursor.next;
				}
			}
		}
		
		public void erase() {
			cursor.prev.next = cursor.next;
			cursor.next.prev = cursor.prev;
			cursor = cursor.next;
		}
		
		public void print() {
			Node tmp = start.next;
			while (tmp != end) {
				System.out.println(tmp.value);
				tmp = tmp.next;
			}
		}
		
		public MyList() {
			start = new Node(-1000000001, null, null);
			end = new Node(-1000000001, start, start);
			start.next = end;
			start.prev = end;
			cursor = end;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		MyList myList = new MyList();
		for (int i = 0; i < q; i++) {
			switch (sc.nextInt()) {
				case 0:
					myList.insert(sc.nextInt());
					break;
				case 1:
					myList.move(sc.nextInt());
					break;
				case 2:
					myList.erase();
					break;
			}
		}
		myList.print();
	}
}



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

int main() {
  int A, B;
  cin >> A >> B;
  
  int a1, a2,a3;
  a1 = A/10000;
  a2 = A%10000/1000;
  a3 = A%1000/100;
  int a = a1*10000 +a2*1000 + a3*100 + a2*10 + a1;
  
  int b1,b2,b3;
  b1 = B/10000;
  b2 = B%10000/1000;
  b3 = B%1000/100;
  int b = b1*10000 + b2*1000 + b3*100 + b2*10 + b1;
  
  int s=1;
  if (a < A)
    s -= 1;
  if (b > B)
    s -= 1;
  
  s += (b1-a1)*100;\
  s += (b2-a2)*10;
  s += (b3-a3);

  cout << s << endl;
}
  

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

int main(){
    int N, M, C, ans = 0, tmp;
    std::cin >> N >> M >> C;
    std::vector<int> B(M);
    std::vector<std::vector<int>> A(N, std::vector<int>(M));
    for(auto i = 0; i < M; i++){
        std::cin >> B.at(i);
    }
    for(auto i = 0; i < N; i++){
        for(auto j = 0; j < M; j++){
            std::cin >> A.at(i).at(j);
        }
    }

    for(auto i = 0; i < N; i++){
        tmp = A.at(i).at(0) * B.at(0);
        for(auto j = 1; j < M; j++){
            tmp += A.at(i).at(j) * B.at(j);
        }
        tmp += C;
        if(tmp > 0){
            ans++;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
var c : array[1..50] of char;
    n, k : integer;
    i : integer;
begin
  read(n, k);
  readln();
  for i := 1 to n do read(c[i]);
  if c[k] = 'A' then c[k] := 'a';
  if c[k] = 'B' then c[k] := 'b';
  if c[k] = 'C' then c[k] := 'c';
  for i := 1 to n do write(c[i]);
end.


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string A;	cin>>A;
	if(A=="RRR")	cout<<"3"<<endl;
	else if(A=="RRS"||A=="SRR")	cout<<"2"<<endl;
	else if(A=="SSS")	cout<<"0"<<endl;
	else cout<<"1"<<endl;


    return 0;
}



Measured memory_bytes: 3588
def chkprime(num):
    isprime = False
    for i in range(2, num):
        if num % i == 0:
            isprime = True
            continue
        else:
            pass
    return(isprime)

a = int(input())
while True:
    if chkprime(a):
        a += 1
    else:
        break

print(a)

Measured memory_bytes: 2940
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int ans  = 0;

        for(int i = 1; i <= n ; i++){
            if(i >= 10 && i <= 99) continue;
            if(i >= 1000 && i <= 9999) continue;
            if(i == 100000) continue;

            ans++;
        }

        System.out.println(ans);
        return;
    }
}

Measured memory_bytes: 22608
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<bitset>
#include<map>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#define INF 0x3f3f3f3f
#define inf 2*0x3f3f3f3f
#define llinf 1000000000000000000
#define pi acos(-1.0)
#define mod 1000000007
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lrt rt<<1
#define rrt rt<<1|1
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define lb(x) (x&-x)
#define gi(x) scanf("%d",&x)
#define gi2(x,y) scanf("%d%d",&x,&y)
#define gll(x) scanf("%lld",&x)
#define gll2(x,y) scanf("%lld%lld",&x,&y)
#define gc(x) scanf("%c",&x)
#define gc2(x,y) scanf("%c%c",&x,&y)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
/***********************************************/
int n,x,y;
vector<int>v[100005];
ll f[100005],num;
void dfs(int x,int pr)
{
    f[x]=1;
    for(int i=0;i<v[x].size();i++)
    {
        if(v[x][i]==pr)continue;
        dfs(v[x][i],x);
        f[x]+=f[v[x][i]]*num;
    }
}
ll cal()
{
    map<ll,int>mm;
    ll sum=0;
    rep(i,1,n+1)
    {
        sum+=mm[f[i]];
        mm[f[i]]++;
    }
    return sum;
}
int main()
{
    gi(n);
    srand((ull)time(0));
    rep(i,0,n-1)
    {
        gi2(x,y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    ll ans=1e16;
    rep(i,0,10)
    {
        num=rand();
        dfs(1,1);
        ans=min(ans,cal());
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 21928
object Main {
  def main(args: Array[String]): Unit = {
    val Array( start, move_count, move_dis ) = scala.io.StdIn.readLine.split( " " ).map{ _.toLong }
    val switch_move_count = Math.abs( start )/move_dis

    if( switch_move_count >= move_count ) println( Math.abs( start ) - move_count*move_dis )
    else {
      val min_diff          = Math.abs( start ) - move_dis*switch_move_count
      val min_diff_switched = move_dis - min_diff
      if( ( move_count - switch_move_count )%2 == 0 ) println( min_diff )
      else                                            println( min_diff_switched )
    }

  }
}

Measured memory_bytes: 54824
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    ll l, r;
    cin >> l >> r;
    ll ans = 9999;
    for (ll i = l; i <= r; i++) {
        for (ll j = l; j <= r; j++) {
            if (i == j) {
                continue;
            }
            ll tmp = (i * j) % 2019;
            ans = min(ans, tmp);
            if (ans == 0) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def grade(m, f, r):
    if m == -1 or f == -1:
        return 'F'
    if m + f >= 80:
        return 'A'
    if m + f >= 65:
        return 'B'
    if m + f >= 50:
        return 'C'
    if m + f >= 30:
        if r >= 50:
            return 'C'
        else:
            return 'D'
    return 'F'

while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    print(grade(m, f, r))



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

int main() {
  int64_t x, k, d, waru, min_x;
  scanf("%lld %lld %lld", &x, &k, &d);
  x = abs(x);
  waru = x/ d;
  if(waru < k) {
    k -= waru;
    x %= d;
    if(abs(x - d) < x) {//-に踏み込んだ方が近い
      k--;
      x = abs(x - d);
    }
    if(k % 2 != 0) {//あと奇数回&&今最も近い
      x = abs(x - d);
    }
  }else {
    x -= k * d;
  }
  cout << x;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}


int main(){
    ll n;
    cin >> n;
    cout << n << ":";
    ll x=n;
    bool f=true;
    for (ll i=2;x!=1;i++){
        if (x==n and i*i>n){
            break;
        }
        while(x%i==0){
            x/=i;
            f=false;
            cout << " " << i;
        }
    }
    if (f){
        cout << " " << n;
    }
    cout << endl;
    return 0;
}



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

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

class BIT {
public:
    ll bit[1000010];
    int bit_size;
    BIT(int n) {
        for (int i = 0; i < n+10; i++) bit[i] = 0;
        bit_size = n;
    }
    void bit_add(int n, ll v) {
        while (n <= bit_size) {
            bit[n] = max(bit[n], v);
            n += n & (-n);
        }
    }
    ll bit_sum(int n) {
        ll ans = 0;
        while (n > 0) {
            ans += bit[n];
            n &= n-1;
        }
        return ans;
    }
    ll bit_max(int n) {
        ll ans = 0;
        while (n > 0) {
            ans = max(ans, bit[n]);
            n &= n-1;
        }
        return ans;
    }
};

int main(void) {
    int n;
    cin >> n;
    BIT bit(n+1);
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        ll cost = bit.bit_max(x-1);
        ll tmp = cost + x;
        ans = max(ans, tmp);
        bit.bit_add(x, tmp);
    }
    ll sum = ((ll)n*(ll)(n+1)) / 2;
    cout << sum - ans << endl;
    return 0;
}

Measured memory_bytes: 3968
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>

using namespace std;
int main() {
	int N;
	int W[100];
	int left = 0, right = 0;
	int ans = 10000;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> W[i];
	}
	for (int T = 0; T < N; T++) {
		for (int i = 0; i < N; i++) {
			if (i <= T) {
				left += W[i];

			}
			else {
				right += W[i];

			}

		}
//			cout << "left = " << left << endl;
//			cout << "right = " << right << endl;
		ans = min(abs(left - right), ans);
		left = 0;
		right = 0;
	}
	cout << ans << endl;




	return(0);
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8


def main():
    n = int(input())
    ls = list(map(int, input().split()))
    l_max = None
    sum_l = sum(l for l in ls)
    for l in ls:
        if l_max is None or l_max < l:
            l_max = l
    if sum_l - l_max > l_max:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>
int a, b, c, x, ways =0;
int mo[4];

void f(int p, int cant, int m){
    if(p >= 2){
        if(m == x){
            ways += 1;
            //for(int i=0; i<3; i++){
               // printf("%d ", mo[i]);
            //}
            //printf("\n");
        }
        return;
    }
    //mo[p] = cant;
    if(p == 0){
        for(int i=0; i<=b; i++){
            f(p+1, i, m+(i*100));
        }
    } else if(p == 1){
        for(int i=0; i<=c; i++){
            f(p+1, i, m+(i*50));
        }
    }
}

int main(){
    scanf("%d %d %d %d", &a, &b, &c, &x);
    for(int i=0; i<=a; i++){
        f(0, i, i*500);
    }
    printf("%d\n", ways);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

Vll fac(200005, -1);

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

void modfactorial(ll n, ll mod)
{
  REP(i, n+1)
  {
    if (i == 0) fac[i] = 1;
    else fac[i] = i * fac[i-1] % mod;
  }
}

ll modnCk(ll n, ll k, ll mod)
{
  ll res = fac[n];
  res = res * modpow(fac[k], mod-2, mod) % mod;
  res = res * modpow(fac[n-k], mod-2, mod) % mod;
  return res;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll H, W, A, B;
  cin >> H >> W >> A >> B;
  modfactorial(H+W+1, MOD);
  ll ans = 0;
  ans += modnCk(B+H-A-1, B, MOD) * modnCk(A+W-B-1, A, MOD);
  ans %= MOD;
  if (B == W-1)
  {
    cout << ans << endl;
    return 0;
  }
  REP(i, H-A-1)
  {
    ans += modnCk(i+B, i, MOD) * modnCk(W-B-2+H-i-1, W-B-2, MOD);
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
/*g++ file.cpp -o file.out*/
/*./file.out*/

#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define LL long long
#define Mod 1000000007
#define L_Mod 17100000013

char s[200005];

int main()
{
    int b,c;
    scanf("%s",s);
    int len=strlen(s);
    for(int i=0;i<len;i++)
    {
        if(s[i]=='A')
        {
            b=i;
            for (int j=i;j<len;j++)
            {
                if(s[j]=='Z')
                {
                    c=j;
                }
            }
            break;
        }
    }
    printf("%d\n",c-b+1);
    return 0;
}



Measured memory_bytes: 384
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int N = Integer.parseInt(scan.next());
    int K = Integer.parseInt(scan.next());
    int Q = Integer.parseInt(scan.next());
    int[] scores = new int[N];
    int[] who = new int[Q];
    int[] ones = new int[N];
    for(int i = 0; i < Q; i++){
      who[i] = scan.nextInt();
    }
    for(int i = 0; i < Q; i++){
      scores[who[i]-1] = scores[who[i]-1]+1;
    }
    for(int n = 0; n < N; n++){
      if((K - Q + scores[n]) <= 0){System.out.println("No");}
      else{System.out.println("Yes");}
    }
  }
 }

Measured memory_bytes: 71768
h, w = [int(n) for n in input().split()]
grid = [input() for _ in range(h)]
row_hashs = set()
column_hashs = set()

for i, row in enumerate(grid):
    for j, ch in enumerate(row):
        if ch == '#':
            row_hashs.add(i)
            column_hashs.add(j)

new_grid = []

for i, row in enumerate(grid):
    if i not in row_hashs:
        continue
    new_grid.append([])
    for j, ch in enumerate(row):
        if j not in column_hashs:
            continue
        new_grid[-1].append(ch)
    new_grid[-1] = "".join(new_grid[-1])

print("\n".join(new_grid))

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  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
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= 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
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s; cin >> s;
  int n = s.size();
  mint dp[n+1][2];
  rep(i, n+1) rep(j, 2) dp[i][j] = 0;
  dp[0][0] = 1;
  rep(i, n) {
    int x = s[i] - '0';
    if(x == 1) {
      dp[i+1][1] += dp[i][0] + dp[i][1]*3;
      dp[i+1][0] += dp[i][0]*2;
    }
    else {
      dp[i+1][1] += dp[i][1]*3;
      dp[i+1][0] += dp[i][0];
    }
  }
  mint ans = dp[n][0]+dp[n][1];
  cout << ans.x << endl;
}


Measured memory_bytes: 5316
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct UnionFind {
  const int n;
  V<> t; // root ? -sz : par
  UnionFind(int n) : n(n), t(n, -1) {}
  int find(int v) { return t[v] < 0 ? v : t[v] = find(t[v]); }
  void unite(int u, int v) {
    if ((u = find(u)) == (v = find(v))) return;
    if (-t[u] < -t[v]) swap(u, v);
    t[u] += t[v];
    t[v] = u;
  }
  bool same(int u, int v) { return find(u) == find(v); }
  int size(int v) { return -t[find(v)]; }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> r(n), c(n); for (int i = 0; i < n; ++i) cin >> r[i] >> c[i], --r[i], --c[i];
  if ((int)set<int>(begin(r), end(r)).size() < n) {
    return cout << -1 << '\n', 0;
  }
  if ((int)set<int>(begin(c), end(c)).size() < n) {
    return cout << -1 << '\n', 0;
  }

  UnionFind uf(n);
  for (int i = 0; i < n; ++i) {
    uf.unite(r[i], c[i]);
  }
  set<int> se;
  for (int i = 0; i < n; ++i) {
    se.insert(uf.find(i));
  }
  int res = n - (int)se.size();
  cout << res << '\n';
}


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

int main(){

    int n;
    double sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        double x; string u;
        cin>>x>>u;
        if(u=="JPY") sum+=x;
        else sum+=x*380000.0;
    }
    cout<<fixed<<setprecision(8)<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    
    int hight = 0;
    int width = 0;
    int x = 0;
    int y = 0;
    int r = 0;
    
    scanf("%d %d %d %d %d",&hight,&width,&x,&y,&r);
    
    bool isYes = true;
    
    if( (hight < (x+r)) || (width < (y+r)) || ((x-r) < 0) || ((y-r) < 0) ){
        isYes = false;
    }
    
    if(isYes != false){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1012
import java.io.*;
import java.util.*;
class Main {
	
	BufferedReader in;
	PrintWriter ob;
	StringTokenizer st;
	long dp[];
	
	public static void main(String args[]) throws IOException {
		new Main().run();
	}
	void run() throws IOException {
		in = new BufferedReader( new InputStreamReader( System.in ) );
		ob = new PrintWriter( System.out );
		solve();
		ob.flush();
	}
	
	void solve() throws IOException {
		int n = ni();
		int k = ni();
		
		if( n == 0 ) {
			ob.println("0");
			return;
		}
		
		int a[] = new int[n];
		dp = new long[n];
		for(int i=0 ; i<n ; i++) { 
			a[i] = ni();
			dp[i] = -1;
		}
			
		long res = rec( a , 0 , n-1 , k );
		ob.println(res);
	}
	
	long rec( int a[] , int i , int size , int k ) {
		if( i > size )
			return Long.MAX_VALUE;
		if( size == i )
			return 0;
		
		if( dp[i] != -1 )
			return dp[i];
		
		long ret = Long.MAX_VALUE;
		for( int j=i+1 ; j<=i+k && j<=size ; j++ )
			ret = Math.min( ret , Math.abs( a[i] - a[j] ) + rec( a , j , size , k ) );
		
		dp[i] = ret;
		return ret;
	}
	
	int ni() throws IOException {
		return Integer.parseInt( nextToken() );
	}
	
	String nextToken() throws IOException {
		if( st == null || !st.hasMoreTokens() )
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
}

Measured memory_bytes: 54132
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    n = int(input())
    a = list(map(int, input().split()))
    c = 0
    for _ in range(n):
        if a[a[_]-1] == _ + 1:
            c += 1
    return c // 2

print(f())


Measured memory_bytes: 16344
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
char s[12];
void dfs(int now,int mx){
	if(now==n+1){
		printf("%s\n", s+1); return;
	}
	for(int i=0;i<=mx+1;i++){
		s[now]=('a'+i);
		dfs(now+1,max(i,mx));
	}
}
int main() {
	cin >> n;
	dfs(1,-1);
}

Measured memory_bytes: 1536
/*{{{*/
//#define HOME
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define F first
#define S second

template<class T> void _R(T &_x) { cin >> _x; }
void _R(int &_x) { scanf("%d", &_x); }
void _R(int64_t &_x) { scanf("%" SCNd64, &_x); }
void _R(double &_x) { scanf("%lf", &_x); }
void _R(char &_x) { scanf(" %c", &_x); }
void _R(char *_x) { scanf("%s", _x); }
template<class T, class U> void _R(pair<T, U> &_x) {_R(_x.F); _R(_x.S);}
void R() {}
template<class T, class... U> void R(T &_head, U &... _tail) { _R(_head); R(_tail...); }

template<class T> void _W(const T &_x) { cout << _x; }
void _W(const int &_x) { printf("%d", _x); }
void _W(const int64_t &_x) { printf("%" PRId64, _x); }
void _W(const double &_x) { printf("%.16f", _x); }
void _W(const char &_x) { putchar(_x); }
void _W(const char *_x) { printf("%s", _x); }
template<class T, class U> void _W(const pair<T, U> &_x) {_W(_x.F); putchar(' '); _W(_x.S);}
template<class T> void _W(const vector<T> &_x) { for (auto i = _x.begin(); i != _x.end(); _W(*i++)) if (i != _x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &_head, const U &... _tail) { _W(_head); putchar(sizeof...(_tail) ? ' ' : '\n'); W(_tail...); }
template<class T, class... U> void DB(const T &_head, const U &... _tail) {
#ifdef HOME
    W('#', _head, _tail...);
#endif
}

#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define RAN(x,n) (x).begin(), (x).begin()+(n)
#define UNIQUE(x) {sort(ALL(x)); (x).erase(unique(ALL(x)), (x).end());}

#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
//#define ITER(i,t) for (auto i = t.begin(); i != t.end(); ++i)
#define IT3(i,st,ed) for (auto i = st; i != ed; ++i)
#define IT2(i,range) IT3(i,range)

#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define MS(X, v) memset((X), (v), sizeof((X)))

template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

inline int LG (const unsigned int &_x) { return 31-__builtin_clz(_x); }  // floor: LG(x), ceil: LG(x-1)+1
/*}}}*/

ll n, k;
vector<ll> as, fs;

int main(){
    R(n, k);
    as.assign(n, 0), fs.assign(n, 0);
    FOR(i, n) R(as[i]);
    FOR(i, n) R(fs[i]);

    sort(ALL(as));
    sort(ALL(fs), [](ll a, ll b){ return a > b; });

    ll left = 0, right = 1LL << 50;
    while(left < right){
        ll mi = (left + right) / 2;

        vector<ll> gs(ALL(fs));
        FOR(i, n) gs[i] = mi / gs[i];
        ll sum = 0;
        FOR(i, n)
            if(as[i] > gs[i]) sum += as[i] - gs[i];
        bool check = sum <= k;

        if(check) right = mi;
        else left = mi + 1;
    }

    W(left);

    return 0;
}


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

typedef long long ll;

int main() {
    int n; cin >> n;
    string s, t; cin >> s >> t;
    for (int i=0; i<n; ++i) {
        if (s.substr(i, n-i)==t.substr(0, n-i)) {
            cout << n+i;
            return 0;
        }
    }
    cout << 2*n;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#dp9 #Sushi

import sys
import bisect
input = sys.stdin.readline
def LI(): return list(map(int,input().split()))
def LIR(n): return [LI() for _ in range(n)]

def J():
    n = int(input())
    a = LI()
    a.sort()
    one = bisect.bisect_right(a,1)
    two = bisect.bisect_right(a,2) - one
    three = n - one - two

    #dp[i][j][k] := 残り1個の皿がi枚、2個の皿がj枚、3個の皿がk枚の状態から
    #               寿司をすべてなくすのに必要な操作回数の期待値
    dp = [[[0.0]*(n+1) for _ in range(n+1)] for _ in range(n+1)]
    for k in range(three+1):
        for j in range(two+three+1 - k):
            for i in range(one+two+three+1-k-j):
                if i == 0 and j == 0 and k == 0:
                    continue
                tmp = n*1.0
                if i > 0:
                    tmp += i*dp[i-1][j][k]
                if j > 0:
                    tmp += j*dp[i+1][j-1][k]
                if k > 0:
                    tmp += k*dp[i][j+1][k-1]
                dp[i][j][k] = tmp/(i+j+k)
    print(dp[one][two][three])
if __name__ == '__main__':
    J()


Measured memory_bytes: 253704
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define in insert
#define REP(i,n) for (int i = 1; i <= n; i++)
#define matrix vector<vector<ll> > 
using namespace std;
 
const ll N = 1e5+2;
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll LOG = 25;

long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll par[1005];


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	ll n,k;
	cin >> n >> k;
	ll a[k+1];
	vector<bool> done(10,false);
	for(int i =1;i<=k;i++){
		cin >> a[i];
		done[a[i]]=true;
	}
	for(ll x = n;;x++){
		bool poss=true;
		ll y = x;
		while(y){
			if(done[y%10]){
				poss=false;break;
			}
			y/=10;
		}
		if(poss){
			cout<<x<<endl;
			exit(0);
		} 
	}

	return 0;
}

Measured memory_bytes: 256