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

using namespace std;

int main() {
	int n, k;
	string S, ans;
	cin >> n >> S >> k;
	
	char select = S[k - 1];
	for (int i = 0; i < n; i++) {
		if (S[i] == select) {
			ans += S[i];
		}
		else {
			ans += "*";
		}
	}
	cout << ans << endl;
}

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

const int maxn=106;
int n,m;
int f[maxn][maxn];
char g[maxn][maxn],c;

int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j) {
			c=getchar();
			while(c!='.'&&c!='#') c=getchar();
			g[i][j]=c;
		}
	memset(f,127,sizeof f);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j) {
			if(i==1&&j==1) f[i][j]=0;
			else f[i][j]=min(f[i-1][j]+(g[i-1][j]!=g[i][j]),f[i][j-1]+(g[i][j-1]!=g[i][j]));
		}
	if(f[n][m]==0) {
		if(g[1][1]=='#') printf("1");
		else printf("0");
	}
	else {
		if(g[1][1]=='.'&&g[n][m]=='.') printf("%d",f[n][m]>>1);
		else if(g[1][1]=='.'||g[n][m]=='.') printf("%d",(f[n][m]+1)>>1);
		else printf("%d",(f[n][m]+2)>>1);
	}
}

Measured memory_bytes: 256
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});
process.stdin.on('end', () => {
  const [size, ...lines] = content
    .trim()
    .split('\n')
    .map(line => line.split(' ').map(n => parseInt(n, 10)));
  
  const [n, m, l] = size;
  const matA = lines.slice(0, n);
  const matB = lines.slice(n);
  const result = matMul(matA, matB);
  console.log(result.map(row => row.join(' ')).join('\n'));
});

const matMul = ([fst, ...rest], matB) => {
  if (fst === undefined) {
    return [];
  }

  const invMatB = invert(matB);
  return [
    invMatB.map(
      row => row.reduce((prev, cur, i) => prev + cur * fst[i], 0)
    ),
    ...matMul(rest, matB)
  ];
};

const invert = mat => {
  const inverted = [];
  for (let i = 0; i < mat[0].length; i++) {
    const row = [];
    for (let j = 0; j < mat.length; j++) {
      row.push(mat[j][i]);
    }

    inverted.push(row);
  }

  return inverted;
};



Measured memory_bytes: 41468
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<62)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/
constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m;
    cin>>n>>m;
    
    ll big=n>m?n:m;
    ll small=n>m?m:n;
    
    rep(i,big){
        cout<<small;
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAX_NUM = 2000000;
int main(){
    int N;
    cin >> N;
    int elements[MAX_NUM];
    int i;
    for(i = 0; i < N; i++){
        cin >> elements[i];
    }
    int k;
    for(k = 0; k < N - 1; k++){
        cout << elements[k] << " " ;
    }
    cout << elements[k] << endl;
    
    int key;
    for(i = 1; i < N ; i++){
        key = elements[i];
        int j;
        for(j = i - 1; j >= 0; j--){
            if(elements[j] > key){
                elements[j+1] = elements[j];

            }else{
                break;
            }
        }
        elements[j+1] = key;
        
        for(k = 0; k < N - 1; k++){
            cout << elements[k] << " " ;
        }
        cout << elements[k] << endl;
    }
    return 0;
}



Measured memory_bytes: 3092
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

const int N=255,Mo=1e9+7;

int n,k,t,f[N],C[N][N],ans;
char st[N];

void pre(int N) {
	fo(i,0,N) {
		C[i][0]=1;
		fo(j,1,i) C[i][j]=(C[i-1][j]+C[i-1][j-1])%Mo;
	}
}

void calc() {
	int sum=0,tr=t,tb=t;
	fo(i,1,k) {
		if (st[i]=='r'&&tr) tr--;
		else if (st[i]=='b'&&f[tb]>1&&tb>tr) sum+=f[tb]-2,tb--;
		else if (sum) sum--;
	}
	while (f[tb]==1) tb--;
	if (tr||tb||sum) return;

	int ret=1;
	for(int l=1,r=0;l<=t;l=r+1) {
		while (r<t&&f[r+1]==f[l]) r++;
		ret=(ll)ret*C[r][r-l+1]%Mo;
	}

	int cnt=0,ulm=0;
	fo(i,1,t) {
		cnt+=(f[i]==1?1:f[i]*2-3)+1;
		ulm+=(f[i]==1?1:f[i]*2-3)+1;
		ulm+=2*(f[i]>1);
	}
	cnt--;ulm++;
	(ans+=(ll)ret*C[n-cnt+ulm-1][ulm-1]%Mo)%=Mo;
	//fo(i,1,t) printf("%d ",f[i]);printf("%d\n",ans);
}

void dfs(int x,int y,int la) {
	calc();
	++t;
	if (la==1&&x+2<=n+1&&y+1<=k) {
		f[t]=1;
		dfs(x+2,y+1,1);
	}
	for(int i=max(la,2);;i++) {
		if (y+i>k) break;
		if (x+2*i-2>n+1) break;
		f[t]=i;
		dfs(x+2*i-2,y+i,i);
	}
	t--;
}

int main() {
	scanf("%d%d",&n,&k);
	pre(250);
	scanf("%s",st+1);
	dfs(0,0,1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<ll> a(m);
    rep(i, m) cin >> a[i];
    
    vector<ll> A(n+1);
    rep(i, m) A[a[i]] = -1;

    A[0] = 1;
    A[1] = A[1] < 0 ? -1 : 1;

    ll MOD = 1000000007;

    for (int i = 2; i <= n; i++) {
        if (A[i] < 0) {
            // if (i > n - 12) {
            //     cout << A[i] << endl;
            // }
            continue;
        }
        if (A[i - 1] >= 0) A[i] += A[i - 1] % MOD;
        if (A[i - 2] >= 0) A[i] += A[i - 2] % MOD;
        A[i] %= MOD;
        // if (i > n - 12) {
        //     cout << A[i] << endl;
        // }
    }

    put(A[n]);
    

    return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
const int maxn = 1e6 + 10;

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> nums(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> nums[i];
        nums[i] += nums[i - 1];
    }
    vector<ll> res;
    ll ans = 0;
    for (int i = 0; i < nums.size() - 1; ++i) {
        for (int j = i + 1; j < nums.size(); ++j) {
            res.push_back(nums[j] - nums[i]);
        }
    }
    for (int i = 40; i >= 0; --i) {
        ll p = pow(2, i);
        int cnt = 0;
        for (auto& x : res) {
            if (((ans + p) & x) == ans + p) ++cnt;
        }
        if (cnt >= k) ans += p;
    }
    cout << ans << endl;
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

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

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

    int n, m;
    cin >> n >> m;
    vector<vector<int> > graph(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> dist(n, -1);
    queue<int> que;
    vector<int> pre(n, -1);

    dist[0] = 0;
    que.push(0);

    while(!que.empty()) {
        int v = que.front();
        que.pop();
        for (int u : graph[v]) {
            if (dist[u] != -1)
                continue ;
            dist[u] = dist[v] + 1;
            que.push(u);
            pre[u] = v;
        }
    }

    cout << "Yes" << '\n';
    for (int i = 1; i < n; i++)
        cout << pre[i] + 1 << '\n';
    return 0;
}

Measured memory_bytes: 10524
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
const int INF = 1e9;
const int MOD = 1e9+7;

string N;
int K;
int dp[110][2][110];

ll solve(int k = 0, bool smaller = false, int sum = 0)
{
    if(dp[k][smaller][sum] != -1) return dp[k][smaller][sum];
    if(sum > K) return 0;
    if(k == N.length()) return sum == K;
    int x = N[k] - '0';
    int r = (smaller) ? 9 : x;
    int ret = 0;
    for(int i = 0; i <= r; i++)
    {
        ret += solve(k+1, smaller || i < r, sum + min(1, i));
    }
    return dp[k][smaller][sum] = ret;
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> N >> K;
    memset(dp, -1, sizeof(dp));
    cout << solve() << endl;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(ll i = a; i < n; i++)

#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#include<cassert>
#include<stack>
#include<deque>
#include<list>
#include<sstream>
#include<unordered_map>
#include<time.h>
#include<functional>
#pragma comment(linker, "/STACK:8809999999")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<ld, ld> pld;
typedef pair<pll, ll> ppll;
typedef pair<pll, pll> ppp;
typedef vector<vector<vector<ll>>> vvv;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const ll settled = 400007;



int main()
{
	ios_base::sync_with_stdio(false); cout.tie(NULL);
#ifndef overlord
	/*freopen("capitals.in", "r", stdin);
	freopen("capitals.out", "w", stdout);*/
#else
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll k, a, b;
	cin >> k >> a >> b;
	
	if (a >= b-2 || k <= a)
	{
		cout << k + 1;
		return 0;
	}

	ll sum = 1;
	k -= a - 1;
	sum = a;
	sum += (b - a)*(k / 2);
	sum += k % 2;
	cout << sum;

	return 0;
}

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

int main(){
	char a[101], b[101], c[101];
	scanf("%s %s %s", a, b, c);
	
	int x = strlen(a), y = strlen(b);
	
	if((a[x-1] == b[0]) && (b[y-1] == c[0]))
		printf("YES\n");
	else
		printf("NO\n");
		
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
const int N=52;
int a[N], slack[N];
template<class Type> Type read() {
	int a;
	bool b;
	unsigned char c;
	while(c=getchar(), c-'0'>9&c!='-');
	for(a=(b=c=='-')?0:c-'0'; (c=getchar()-'0')<=9; a=a*10+c);
	return b?-a:a;
}
int main() {
	int (*rd)()=read<int>, n=rd(), k=rd();
	std::vector<int> ans;
	for(int i=1; i<=n; ++i) a[i]=std::max(0, k+1-rd());
	int argmax=std::max_element(a+1, a+n+1)-a;
	if(a[argmax]*2>k+1||std::accumulate(a+1, a+n+1, 0)>k) {
		puts("-1");
		return 0;
	}
	for(int i=1; i<=k; i+=2) {
		if(!a[argmax]) {
			argmax=std::max_element(a+1, a+n+1)-a;
			if(a[argmax]==0) break;
		}
		--a[slack[i]=argmax];
	}
	for(int i=2; i<=k; i+=2) {
		if(!a[argmax]) {
			argmax=std::max_element(a+1, a+n+1)-a;
			if(a[argmax]==0) break;
		}
		--a[slack[i]=argmax];
	}
	for(int i=0; i<=k; ++i) {
		for(int j=1; j<=n; ++j)
			if(j!=slack[i]&&j!=slack[i+1])
				ans.push_back(j);
		if(slack[i+1]) ans.push_back(slack[i+1]);
	}
	printf("%d\n", ans.size());
	for(int i: ans) printf("%d ", i);
	puts("");
	return 0;
}


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

const string day[] = {"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};

int dd[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main()
{
  int m, d;
  while (cin >> m >> d) {
    if (m == 0 && d == 0)
      break;
    for (int i = 1; i < m; ++i)
      d += dd[i-1];
    cout << day[d%7] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.StringTokenizer;
public class Main {
	static int[][] next = {{0, 1},{1, 0},{-1, 0},{0, -1}};
 
	public static void main(String[] args) throws IOException  {
		// TODO Auto-generated method stub
		InputReader in = new InputReader();
		while(true) {
			int ans = 0;
			 int n = in.nextInt();
			 int m = in.nextInt();
			 if(n == 0 && m == 0) break;
			 char[][] s = new char[n][m];
			 for(int i = 0; i < n; i ++) {
				 char[] tmp =in.next().toCharArray();
				 for(int j = 0; j < m; j ++) {
					 s[i][j] = tmp[j];
				 }
			 }
	 
			 for(int i = 0; i < n; i ++) {
				 for(int j = 0; j < m; j ++) {
					if(s[i][j] != '.') {
						dfs(s, i, j );
						ans ++ ;
					}
				 }
			 }
			 System.out.println(ans);
		}
		
	}
	public static void dfs (char[][] s, int x, int y ) {
		char tmp = s[x][y];
		s[x][y] = '.';
		for(int k = 0; k < 4; k ++) {
			int nx = next[k][0] + x;
			int ny = next[k][1] + y;
			if(nx < 0 || nx >= s.length || ny < 0  || ny >= s[0].length) {
				continue;
			}
			if(s[nx][ny] == tmp) {
				dfs(s, nx, ny);
			}
		}
	}
 
}
class InputReader
{
    BufferedReader buf;
    StringTokenizer tok;
    InputReader()
    {
        buf = new BufferedReader(new InputStreamReader(System.in));
    }
    boolean hasNext()
    {
        while(tok == null || !tok.hasMoreElements()) 
        {
            try
            {
                tok = new StringTokenizer(buf.readLine());
            } 
            catch(Exception e) 
            {
                return false;
            }
        }
        return true;
    }
    String next()
    {
        if(hasNext()) return tok.nextToken();
        return null;
    }
    int nextInt()
    {
        return Integer.parseInt(next());
    }
    long nextLong()
    {
        return Long.parseLong(next());
    }
    double nextDouble()
    {
        return Double.parseDouble(next());
    }
    BigInteger nextBigInteger()
    {
        return new BigInteger(next());
    }
    BigDecimal nextBigDecimal()
    {
        return new BigDecimal(next());
    }
}


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

int main()
{
  	vector<int> towers;
  	towers.push_back(1);
  	for(int i=2 ; i<=999 ; ++i)
  	{
  	    towers.push_back(towers[i-2]+i);
  	    //cout<<towers[i-1]<<" ";
  	}
  	int w,e;
  	cin>>w>>e;
  	for(int i=1 ; i<towers.size() ; ++i)
  	{
        if(abs(towers[i-1]-w)==abs(towers[i]-e))
        {
            cout<<towers[i]-e<<endl;
            return 0;
        }
  	}
  	cout<<1<<endl;
  	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	int A[200001];
	map<int,int> Anum;
	scan(N);
	rep(i,N){
		scan(A[i]);
		Anum[A[i]]++;
	}
	sort(A,A+N);
	//bool choosed[200001]={};
	int ans=0;
	for(int i=N-1;i>=0;i--){
		int taiou=(1<<((int)(log2(A[i])+eps)+1))-A[i];
		if((A[i]!=taiou&&Anum[A[i]]>0&&Anum[taiou]>0)||(A[i]==taiou&&Anum[taiou]>1)){
			Anum[taiou]--;
			Anum[A[i]]--;
			ans++;
			//printf("%d %d\n",A[i],taiou);
		}
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 19968
package main

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

func main() {
	N := nextInt()
	A := make([]int64, N+1)

	for i := 1; i <= N; i++ {
		A[i] = nextInt64()
	}

	t := mint(1)
	dp := [3]int64{0, 0, 0}

	for i := 1; i <= N; i++ {
		c := mint(0)
		for j := 0; j < 3; j++ {
			if dp[j] == A[i] {
				if c == 0 {
					dp[j]++
				}
				c++
			}
		}
		t = t.mul(c)

		// ソート
		for k := 0; k < 3; k++ {
			for l := k + 1; l < 3; l++ {
				if dp[l] < dp[k] {
					dp[k], dp[l] = dp[l], dp[k]
				}
			}
		}
	}

	fmt.Println(t)
}

type mint int64

var mod = mint(1e9 + 7)

// add は a + bを返します
func (a mint) add(b mint) mint {
	return (a + b) % mod
}

// sub は a - bを返します
func (a mint) sub(b mint) mint {
	return (a - b + mod) % mod
}

// mul は a * bを返します
func (a mint) mul(b mint) mint {
	return (a * (b % mod)) % mod
}

// div は a/bを返します
func (a mint) div(b mint) mint {
	return a.mul(b.inv())
}

// inv は aの逆元を返します
func (a mint) inv() mint {
	// 拡張ユークリッドの互除法
	b := mod
	u := mint(1)
	v := mint(0)
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	return (u + mod) % mod
}

// pow は a ^ bを返します
func (a mint) pow(b mint) mint {
	ans := mint(1)

	for b != 0 {
		if b&1 == 1 {
			ans = ans.mul(a)
		}
		a = a.mul(a)
		b = b >> 1
	}
	return ans
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

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

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 2560
from math import gcd
K = int(input())
Sum = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            if i==j and j==k:
                Sum += i
            elif i!=j and j!=k and k!=i:
                Sum += gcd(i,gcd(j,k))*6
            else:
                Sum += gcd(i,gcd(j,k))*3
                
print(Sum)

Measured memory_bytes: 9192
// 嘘っぽい
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

typedef pair<int,int> pii;
int ans = 1<<30, a[18], b[18], n;
vector<pii> u, d;
vector<int> take, res;

int main(){
    cin >> n;
    for(int i = 0; i < n; i++)  cin >> a[i];
    for(int i = 0; i < n; i++)  cin >> b[i];
    for(int i = 0; i < n; i++){
        if(i%2 == 0)    u.push_back({a[i], i}), d.push_back({b[i], i});
        else            d.push_back({a[i], i}), u.push_back({b[i], i});
    }
    sort(u.begin(), u.end());
    sort(d.begin(), d.end());
    for(int i = 0; i < 1<<n; i++){
        vector<pii> val;
        vector<bool> used(n, 0);
        for(int j = 0; j < n; j++)  if(i>>j&1)  val.push_back(u[j]), used[u[j].second] = true;
        if(val.size() != (n+1)/2)   continue;
        vector<pii> res;
        for(int j = 0; j < n; j++){
            if(!used[j]){
                if(j%2 == 0)    res.push_back({b[j], j});
                else            res.push_back({a[j], j});
            }
        }
        sort(res.begin(), res.end());
        vector<int> value, index;
        for(int j = 0; j < n/2; j++){
            value.push_back(val[j].first);
            value.push_back(res[j].first);
            index.push_back(val[j].second);
            index.push_back(res[j].second);
        }
        if(n%2 == 1)    value.push_back(val[n/2].first), index.push_back(val[n/2].second);
        bool ok = true;
        for(int j = 1; j < n; j++)  ok &= value[j-1] <= value[j];
        if(!ok) continue;
        int tmp = 0;
        for(int j = 0; j < n; j++){
            for(int k = 0; k+1 < n-j; k++){
                if(index[k] > index[k+1]){
                    swap(index[k], index[k+1]);
                    tmp++;
                }
            }
        }
        ans = min(ans, tmp);
    }
    cout << (ans == 1<<30 ? -1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 256
(n, m), h, *r = [[*map(int, i.split())] for i in open(0)]
g =[] + h

for i in r:
    g[i[0]-1] *= h[i[0]-1] > h[i[1]-1]
    g[i[1]-1] *= h[i[1]-1] > h[i[0]-1]
print(len([i for i in g if i !=0]))



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

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();

			for (int i = 0; i < n; i++) {
				int a = sc.nextInt();
				if (map.containsKey(a)) {
					map.put(a, map.get(a) + 1);
				} else {
					map.put(a, 1);
				}

				if (map.containsKey(a - 1)) {
					map.put(a - 1, map.get(a - 1) + 1);
				} else {
					map.put(a - 1, 1);
				}

				if (map.containsKey(a + 1)) {
					map.put(a + 1, map.get(a + 1) + 1);
				} else {
					map.put(a + 1, 1);
				}
			}

			int max = 0;
			for (int i : map.keySet()) {
				if (max < map.get(i)) {
					max = map.get(i);
				}
			}

			System.out.println(max);
		}
	}
}


Measured memory_bytes: 65668
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
a,b = map(str,input().split())
a = int(a)
bint,bdec = b.split('.')
bint = int(bint)
bdec = int(bdec)
ans = a*bint+(a*bdec//100)
print(ans)

Measured memory_bytes: 9200
#include<stdio.h>

#define M 10000

int liner_search(int[], int, int);

int main(void) {
  int i, n, S[M+4], q, key, sum=0;

  scanf("%d", &n);
  for(i=0; i<n; i++) {
    scanf("%d", &S[i]);
  }
  scanf("%d", &q);
  for(i=0; i<q; i++) {
    scanf("%d", &key);
    if(liner_search(S, n, key)) sum++;
  }
  printf("%d\n", sum);

  return 0;
}

int liner_search(int S[], int n, int key) {
  int i=0;
  S[n]=key;
  while(S[i]!=key) i++;
  
  return i!=n;
}



Measured memory_bytes: 2148
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<map>
#include<cmath>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 100050
#define ll long long
#define inf int(1e9)
#define mm 1000000007
#define low(x) x&(-x)
using namespace std;
int read(){
    int x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
int s[2];
int n,p;
ll Pow[maxn];
int main(){
	n=read(); p=read();
	rep(i,1,n) s[read()%2]++;
	Pow[0]=1; rep(i,1,50) Pow[i]=Pow[i-1]*2;
	if (p==0) {
		ll ans=0;
		if (s[1]>=1) ans=Pow[s[0]]*Pow[s[1]-1];
		else ans=Pow[s[0]];
		printf("%lld\n",ans);
	}
	else {
		if (s[1]==0) puts("0");
		else printf("%lld\n",Pow[s[1]-1]*Pow[s[0]]);		
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	string s;
	int n, i, j, k, minn, c, c1, c2;
	cin >> n >> s;
	minn = 0; c = 0; c1 = 0; c2 = 0;
	for (auto ch : s) {
		if (ch == '(') c1++, c++;
		else c2++, c--;

		minn = min(minn, c);
	}
	for (i = 0; i < -minn; i++) cout << "(";
	cout << s;
	c1 += -minn;
	for (i = 0; i < c1 - c2; i++) cout << ")";
	cout << "\n";

	return 0;
}


Measured memory_bytes: 256
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	int N, M;
	int cnt = 0;
	vector<int>list1, list2;

	cin >> N >> M;

	for (int i = 2, i2=0; i2 < N; i+=2, i2++) {
		list2.push_back(i);
	}

	for (int j = 1, j2 = 0; j2 < M; j += 2, j2++) {
		list1.push_back(j);
	}

	for (int i = 0; i < list1.size(); i++) {
		for (int j = 0; j < list2.size(); j++) {
			if (list1[i] + list2[j] % 2 == 0)cnt++;
		}
	}
	
	for (int i = 0; i < list1.size(); i++) {
		for (int j = 0; j < list1.size(); j++) {
			if (i == j)continue;
			if ((list1[i] + list1[j]) % 2 == 0)cnt++;
		}
	}

	for (int i = 0; i < list2.size(); i++) {
		for (int j = 0; j < list2.size(); j++) {
			if (i == j)continue;
			if ((list2[i] + list2[j]) % 2 == 0)cnt++;
		}
	}
	cout << cnt/2 << endl;




	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    if (a >= 13) {
        cout << b << endl;
    } else if (a >= 6) {
        cout << b / 2 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

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

using namespace std;

using ll = long long;

int main(){
    ll n; cin >> n;
    ll arr[n];
    for(ll i = 0; i < n; ++i){
        cin >> arr[i];
    }
    ll uk = accumulate(arr, arr + n, 0), min1 = LONG_MAX, min2 = LONG_MAX;
    ll cur = 0;
    for(ll i = 0; i < n - 1; ++i){
        cur += arr[i];
        min1 = min(min1, abs(uk - cur - cur));
    }
    cur = 0;
    for(ll i = n - 1; i > 0; --i){
        cur += arr[i];
        min2 = min(min2, abs(uk - cur - cur));
    }
    cout << min(min1, min2);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define ll long long
const int mod=1e9+7;
using namespace std;
const int N=17;
inline int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,m,sn,a[20],cnt[1<<N];
ll f[20][1<<N],fac[1<<N],inv[1<<N],ans;
ll c(ll n,ll m){
	if(n<m) return 0;
	return fac[n]*inv[m]%mod*inv[n-m]%mod; 
}
int main(){
	n=read(),m=read(),sn=1<<n;
	inc(i,1,m) a[i]=read();
	reverse(a+1,a+m+1);
	fac[0]=inv[0]=inv[1]=1;
	inc(i,1,sn) fac[i]=fac[i-1]*i%mod;
	inc(i,2,sn) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	inc(i,2,sn) inv[i]=inv[i-1]*inv[i]%mod;
	f[0][0]=1;
	inc(i,0,m-1){
		inc(j,0,sn-1){
			if(!f[i][j]) continue;
			(f[i+1][j]+=f[i][j])%=mod;
			inc(k,0,n-1){
				if(j&(1<<k)) continue;
				int left=sn-j-a[i+1];
				(f[i+1][j|(1<<k)]+=f[i][j]*c(left,(1<<k)-1)%mod*fac[1<<k]%mod)%=mod;
			}
		}
	}
	inc(i,0,sn-1){
		cnt[i]=cnt[i>>1]+(i&1);
		f[m][i]=f[m][i]*fac[sn-i-1]%mod;
		(ans+=(cnt[i]&1)?mod-f[m][i]:f[m][i])%=mod;
	}
	printf("%lld\n",ans*sn%mod);
}

Measured memory_bytes: 19968
#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 SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

const string D_blue    = "\x1b[36m";
const string D_green   = "\x1b[32m";
const string D_red     = "\x1b[31m";
const string D_yellow  = "\x1b[33m";
const string Db_red    = "\x1b[41m";
const string Db_yellow = "\x1b[43m";
const string D_end     = "\x1b[39m";
const string Db_end    = "\x1b[49m";

int main (){
  int n;
  while (cin >> n){
    int A[n+2];
    int sum = 0;
    A[0] = 0;
    A[n+1] = 0;
    FOR(i,1,n+1){
      int in;
      scanf("%d",&in);
      A[i] = in;
      sum += abs(in - A[i-1]);
    }
      sum += abs(A[n+1] - A[n]);

    FOR(i,1,n+1){
      int ans = sum;
      ans -= abs(A[i] - A[i-1]);
      ans -= abs(A[i+1] - A[i]);
      ans += abs(A[i+1] - A[i-1]);
      cout << ans << endl;
    }
    
  }
  return 0;
}


Measured memory_bytes: 1664
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

ll modpow(ll a, ll b){
    ll r = 1;
    while(b){
        r = r*((b%2)?a:1)%mod;
        a = a*a%mod;
        b>>=1;
    }
    return r;
}

ll comb(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mod, factr[i]=factr[i-1]*inv[i]%mod;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mod*factr[N_-C_]%mod;
}

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;cin>>n>>k;
    rep(i,0,k){
        if (n-k<i) cout<<0<<endl;
        else {
            cout<<comb(n-k+1,i+1)*comb(k-1,i)%mod<<endl;
        }
    }
}

Measured memory_bytes: 12980
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,n,d;
	cin>>n>>d;

	k=(2*d+1);
	ll l=ceil((n*1.0)/(1.0*k));
	cout<<l;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff          first
#define ss          second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
    int a;
    cin >> a;
    cout << a + a*a + a*a*a;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3612
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N, K;
	std::cin >> N >> K;
	std::vector<int64_t> h(N);
	for (int64_t i = 0; i < N; i++) {
		std::cin >> h[i];
	}

	int64_t cnt = 0;
	for(int64_t i = 0; i < N; i++) {
		if(h[i] >= K) {
			cnt++;
		}
	}
	std::cout << cnt << std::endl;
}

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


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

int main(){
  int N;
  cin>>N;
  vector<int> dan(N);
  priority_queue<int> streak;
  int H;
  cin>>H;
  dan.at(0)=H;
  int count=0;
  if(N==1) cout<<0<<endl;
  else{
  for(int i=1; i<N; i++){
    int H;
    cin>>H;
    dan.at(i)=H;
    if(dan.at(i)<=dan.at(i-1)) count++;
    else{
        streak.push(count);
        count=0;
    }
    if(i==N-1) streak.push(count);
  }
  cout<<streak.top()<<endl;
  }
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int H, W, N;
	cin >> H >> W >> N;
	vector<int> arrow_x = {1, 0, -1, 0};
	vector<int> arrow_y = {0, 1, 0, -1};
	int arrow = 0;
	vector<vector<int>> map(H, vector<int>(W, 0));

	int current_x = -1;
	int current_y = 0;

	for (int i = 0; i < N; i++)
	{
		int color;
		cin >> color;

		for (; color;)
		{
			int next_x = current_x + arrow_x[arrow];
			int next_y = current_y + arrow_y[arrow];

			if (next_x < 0 || W <= next_x || next_y < 0 || H <= next_y)
			{
				arrow = (arrow + 1) % 4;
				continue;
			}

			if (map[next_y][next_x] != 0)
			{
				arrow = (arrow + 1) % 4;
				continue;
			}

			map[next_y][next_x] = i + 1;
			current_x = next_x;
			current_y = next_y;
			color--;
		}
	}

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			cout << map[i][j] << " ";
		}
		cout << endl;
	}
	return;
}

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

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1ll << 60;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

#ifdef WIN32
#define dump(x) cout << #x << " = " << (x) << "\n"
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n"
#else
#define dump(x)
#define debug(x)
#endif

int w, n, now = 0;
vector<PII> v;
PII dp[ 1001 ][ 1001 ];

PII dfs( int now, int g ) {
	if ( now == n ) {
		return MP( 0, w - g );
	}
	if ( dp[ now ][ g ].first >= 0 ) {
		return dp[ now ][ g ];
	}
	PII res = MP( -1, -1 );
	if ( g >= v[ now ].second ) {
		PII tmp = dfs( now + 1, g - v[ now ].second );
		tmp.first += v[ now ].first;
		res = tmp;
	}
	PII tmp = dfs( now + 1, g );
	if ( tmp.first > res.first || ( tmp.first == res.first && tmp.second < res.second ) ) {
		res = tmp;
	}
	return dp[ now ][ g ] = res;
}

void solve() {
	printf( "Case %d:\n", now );
	PII ans = dfs( 0, w );
	printf( "%d\n%d\n", ans.first, ans.second );
}

int main() {
#ifdef WIN32
	printf( "Debug Mode\n" );
#endif
	while ( ~scanf( "%d", &w ) && w ) {
		now++;
		for ( int i = 0; i < 1001; i++ ) {
			for ( int j = 0; j < 1001; j++ ) {
				dp[ i ][ j ] = PII( -1, -1 );
			}
		}
		scanf( "%d", &n );
		v.resize( n );
		for ( int i = 0; i < n; i++ ) {
			scanf( "%d,%d", &v[ i ].first, &v[ i ].second );
		}
		solve();
	}
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  if (s == "Sunny") cout << "Cloudy" << endl;
  if (s == "Cloudy") cout << "Rainy" << endl;
  if (s == "Rainy") cout << "Sunny" << endl;
  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n, k;
int h[100001], dp[100001];
int solve() {
    repc2(i, 2, n) {
        int min_sum = inf;
        rep2(j, max(1, i - k), i) { min_sum = min(min_sum, dp[j] + abs(h[i] - h[j])); }
        dp[i] = min_sum;
    }
    return dp[n];
}
int main() {
    cin >> n >> k;
    reps(i, n) { cin >> h[i]; }
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 1024
n=120
l=[0]*120
s="#"*20
for i in range(input()):b,f,r,v=map(int,raw_input().split());l[b*30+f*10+r-41]+=v
print"",
#i=1;while 1:; i+=1
for i in range(1,121):
 print l[i-1],
 if i==120:break
 if i%30==0:print;print s,
 if i%10==0:print;print"",

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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007

#define trace1(x)                    cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,a,b,n,m;
    cin>>n;
    cin>>a>>b;
    ll p[n];
    for(i=0;i<n;i++)
    cin>>p[i];
    ll cnta=0,cntb=0,cntc=0;
    for(i=1;i<=n;i++)
    {
        if(p[i-1]<=a)
        cnta++;
        else if(p[i-1]<=b && p[i-1]>a)
        cntb++;
        else
        cntc++;
    }
    ll mini=min(cnta,min(cntb,cntc));
    cout<<mini;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 105, M = 1e5 + 5;
const ll LINF = 1e18 + 5;
int n, k, a[N];
constexpr int mod = 1e9 + 7;
ll dp[N][M], sum[M];
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> k;
 	for(int i=1; i<=n; i++) cin >> a[i];
 	for(int i=0; i<=a[1]; i++) dp[1][i] = 1;
 	sum[0] = dp[1][0];
	for(int i=1; i<=k; i++) sum[i] = sum[i-1] + dp[1][i]; 
 	for(int i=2; i<=n; i++)
 	{
 		for(int j=0; j<=k; j++)
 		{
 			if(j<=a[i]) dp[i][j] = (dp[i][j] + sum[j])%mod;
 			else dp[i][j] = (dp[i][j] + (sum[j]-sum[j-a[i]-1]+mod))%mod;
 		}
 		sum[0] = dp[i][0];
 		for(int j=1; j<=k; j++) sum[j] = (sum[j-1] + dp[i][j])%mod;
 	}
 	ll ans = dp[n][k];
 	ans = (ans + mod)%mod;
 	cout << ans;
	return 0;
}


Measured memory_bytes: 79360
#include<cstdio>
#include<algorithm>
#include <vector>
using namespace std;

int main(){
	int H,W,h,w;
	scanf("%d %d\n",&H,&W);
	scanf("%d %d",&h,&w);
	int tmp;
//	if(h>w)tmp=h;
//	else tmp=w;
	printf("%d\n",H*W-h*W-w*H+h*w);
	return 0;
}


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

const int maxN = 2 * (int) 1e5;

int fa[maxN], num[maxN];

int find(int x) {
	return fa[x] == x ? x : fa[x] = find(fa[x]);
}

void merge(int x, int y) {
	int fx = find(x), fy = find(y);
	if (fx != fy) {
		fa[fx] = fy;
		num[fy] += num[fx];		
	}
}



int main() {
	/*

	union find set (?)
	
	. --- . --- . --- . --- .
	
	. --- . --- .
	
	. --- . --- . --- .
	
	. --- . --- . --- . --- . --- . --- .
	
	merge( u, v )
	
	
	

	*/
	
	int n, m;
	cin >> n >> m;
	
	for (int i = 1; i <= n; i++) {
		fa[i] = i;
		num[i] = 1;
	}
	
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		merge(u, v);
	}
	
	//puts("");
	


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


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

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    //5 13
    cout << s.substr(0,5) << " ";
    cout << s.substr(6,7) << " ";
    cout << s.substr(14) << endl;
    
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
# define MOD 1000000000+7
# define INF 1000000000
typedef long long ll;
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }


int main() {
	string x;
	int type = 0;
	map<char, int> m;
	cin >> x;
	rep(i, 4) {
		m[x[i]]++;
		if (m[x[i]] == 1) {
			type++;
		}
	}

	if (type == 2 && m[x[0]] == 2 && m[x[1]] == 2 && m[x[2]] == 2 && m[x[3]] == 2) {
		cout << "Yes" << endl;
	}
	else {

	
		cout << "No" << endl;
	}

	
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	string S;
	cin >> S;

	bool check_a = false;
	bool check_b = false;
	bool check_c = false;

	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == 'a') check_a = true;
		else if (S[i] == 'b') check_b = true;
		else if (S[i] == 'c') check_c = true;
	}

	if (check_a && check_b && check_c)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}

	return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <stdio.h>
#include <cmath>
#define EPS 1e-10
using namespace std;
int main(){
  double a,b,c,d,e,f;

  while(1){
    cin >> a >> b >> c >> d >> e >> f;
    if(cin.eof())break;

    double x = (f*b-c*e)/(b*d-a*e);
    double y = (c - a*x)/b;
    if(abs(x) < EPS)x = 0;
    if(abs(y) < EPS)y = 0;
    printf("%.3f %.3f\n",x,y);
  }
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define distance(x1,y1,x2,y2) sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

template<typename T>
void say(vector<T> s, string t) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << t << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("yes");
	else say("no");
}

void Yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

template<typename T>
void maxi(T & a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T & a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

template<class T> void getVector(vector<T> & v) {
	for (int i = 0; i < v.size(); ++i)
		cin >> v[i];
}

bool in(int w, int x, int r) {
	return x - r >= 0 && x + r <= w;
}

int main() {
	int i = 1;
	int n;
	cin >> n;
	while (n != 0) {
		cout << "Case " << i++ << ": " << n << endl;
		cin >> n;
	}
}

/*Case 1: 3*/


Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
int frog[100005];
int h[100005];
int main()
{
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  frog[0]=0;
  frog[1]=abs(h[0]-h[1]);
  for(int i=2;i<n;i++){
    frog[i]=min(abs(h[i]-h[i-1])+frog[i-1],abs(h[i]-h[i-2])+frog[i-2]);
  }
  cout<<frog[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
n,m=map(int,input().split())
ansct=0
ansflag=[0]*n
miss=[0]*n
missct=0
for i in range(m):
    p,s=map(str,input().split())
    if (s=='AC')and(ansflag[int(p)-1]==0):
        ansflag[int(p)-1]=1
        ansct+=1
        missct+=miss[int(p)-1]
    elif ansflag[int(p)-1]==0:
        miss[int(p)-1]+=1
print(str(ansct)+' '+str(missct))

Measured memory_bytes: 73640
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
//#define int long long

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

	string s;
	cin >> s;
	
	for (size_t i = 0; i < s.size()-8; i++)
	{
		cout << s[i];
	}
	cout << endl;

	return 0;
}


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

int main() {
  int n, h;
  cin >> n >> h;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  int max_a = a[0];
  int cnt = 0;
  rep(i, n) {
    if (h <= 0) {
      cout << cnt << endl;
      return 0;
    }

    if (max_a <= b[i]) {
      h -= b[i];
      cnt++;
    } else {
      break;
    }
  }

  if (h > 0) cnt += ceil((double)h / max_a);
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 4112