akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
using namespace std;



int main() {


	int n,m;
	

	cin >> n;
	cin >> m;
	int l, r;
	int tmpL = 1;
	int tmpR = 100000;
	int ans[100001] = {0};
	
	for (int i = 1; i <= m; i++) {
		cin >> l;
		cin >> r;
		if (tmpL < l)
			tmpL = l;
		if (tmpR > r)
			tmpR = r;

		if (tmpL > tmpR)
			break;
	
	}
	if (tmpL > tmpR)
		printf("0\n");
	else
		printf("%d\n",tmpR-tmpL+1);

	

	
	return 0;
}





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

void solve(){
string s; cin>>s;
int cnt=0;
if(s[0]==s[1]&&s[1]==s[2]&&s[0]=='R') cnt=3;
else if(s[0]==s[1]&&s[0]=='R') cnt=2;
else if(s[1]==s[2]&&s[1]=='R') cnt=2;
else if(s[0]=='R'||s[1]=='R'||s[2]=='R') cnt=1;
cout<<cnt<<endl;
}
int main(){
solve();
}


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

typedef long long ll;
const int N=2e4+5,M=2e4;
ll f[N];
struct dt {
	int w,s,v;
}d[N];

int main() {
	//freopen("1.in","r",stdin);
	//freopen("1.ans","w",stdout);
	
	int n; scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d%d%d",&d[i].w,&d[i].s,&d[i].v);
	sort(d+1,d+n+1,[](const dt &lhs,const dt &rhs){return lhs.s+lhs.w<rhs.s+rhs.w;});
	for(int i=1;i<=n;++i) {
		for(int j=d[i].s;j>=0;--j) if(j+d[i].w<=M) f[j+d[i].w]=max(f[j+d[i].w],f[j]+d[i].v);
	}
	printf("%lld\n",*max_element(f,f+M+1));
	
	return 0;
}


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

public class Main {
	FastScanner in;
	PrintWriter out;

	void solve() {
		String s = in.next();
		out.println(s.substring(0, 4) + " " + s.substring(4));
	}

	void run() {
		try {
			in = new FastScanner(new File("object.in"));
			out = new PrintWriter(new File("object.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().runIO();
			}
		}, "1", 1 << 26).start();
	}
}

Measured memory_bytes: 8432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 111;

char s[N];
int main() {
    map<pair<string,string>,int> ct;
    int n;
    scanf("%d%s", &n, s);
    for (int m = 0; m < 1 << n; m++) {
        string r, b;
        for (int i = 0; i < n; i++) {
            (m & (1 << i) ? r : b).push_back(s[i]);
        }
        ct[{r, b}]++;
    }
    ll ans = 0;
    for (int m = 0; m < 1 << n; m++) {
        string r, b;
        for (int i = 0; i < n; i++) {
            (m & (1 << i) ? r : b).push_back(s[i + n]);
        }
        reverse(r.begin(), r.end());
        reverse(b.begin(), b.end());
        ans += ct[{b, r}];
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 87816
import kotlin.*

fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val k = sc.nextInt()
        val d = sc.list().map { it[0] }

        for (p in n..9999999) {
            val str = p.toString()
            val f = str.all { !d.contains(it) }
            if (f) {
                println(p)
                return
            }
        }
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        if (ptr >= l.size) {
            var s: String
            do {
                s = readLine()!!
            } while (s.isEmpty())
            l = s.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        val s = readLine()!!
        return if (s.isEmpty()) listOf() else s.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


Measured memory_bytes: 41492
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

int cmp (const void *a, const void *b) {
  i32 d = *(i32 *)a - *(i32 *)b;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *a = (i32 *) calloc (n, sizeof (i32));
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
  }
  qsort (a, n, sizeof (i32), cmp);
  i32 ans = 0;
  for (i32 bit = 30; bit >= 1; --bit) {
    i32 i = 0;
    i32 j = n - 1;
    i32 sum = 1 << bit;
    while (i < j) {
      if (a[i] + a[j] == sum) {
	ans++;
	a[i] = a[j] = 0;
	i++;
	j--;
      } else if (a[i] + a[j] < sum) {
	i++;
      } else {
	j--;
      }
    }
    j = 0;
    for (i = 0; i < n; ++i) {
      if (a[i] > 0) {
	a[j++] = a[i];
      }
    }
    n = j;
  }
  printf ("%" PRIi32 "\n", ans);
}

int main (void) {
  run ();
  return 0;
}


Measured memory_bytes: 1788
#include<iostream>

using namespace std;

int main(){
	int m, f, r;
	for (int i = 0; i < 50; i++) {
		cin >> m >> f >> r;
		
		if (m == -1 && f == -1 && r == -1) {
			break;
		}
        else if (m == -1 || f == -1) {
			cout << 'F' << endl;
		}
		else if (m + f >= 80 && m>=0 && f>=0) {
			cout << 'A' << endl;
		}
		else if (m + f < 80 && m + f >= 65 && m>=0 && f>=0) {
			cout << 'B' << endl;
		}
		else if (m + f < 65 && m + f >= 50 && m >= 0 && f >= 0) {
			cout << 'C' << endl;
		}
		else if (m + f < 50 && m + f >= 30 && r < 50 && m >= 0 && f >= 0) {
			cout << 'D' << endl;
		}
		else if (m + f < 50 && m + f >= 30 && r >= 50 && m >= 0 && f >= 0) {
			cout << 'C' << endl;
		}
		else if (m + f < 30 && (m>=0 || f>=0)) {
			cout << 'F' << endl;
		}
	
	}

	return 0;
}




Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    while(cin >> n,n){
        int maxv=0,cnt=0;
        int k;
        for(int i=0;i<n;i++){
            cin >> k;
            if(maxv < k) maxv=k;
            if(k) cnt++;
        }
        if(maxv < 2) cout << "NA" << '\n';
        else cout << cnt+1 << '\n';
    }
    return 0;
}



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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 333

typedef long long ll;
typedef long double ld;

ll w[maxn][maxn];
ll sh[maxn][maxn];

vector<pair<int, pair<int, int> > > v;

int main(){
	int n;
	bool ok = 1;
	ll total = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			scanf("%lld", sh[i] + j);
			w[i][j] = INF;
			v.pb(mp(sh[i][j], mp(i, j)));
		}
		w[i][i] = 0;
	}

	sort(v.begin(), v.end());
	for(int i = 0; i < v.size(); i++){
		int l = v[i].se.fi;
		int d = v[i].se.se;
		
		for(int k = 0; k < n; k++)
			w[l][d] = min(w[l][d], w[l][k] + w[k][d]);

		if(w[l][d] < sh[l][d])
			ok = 0;

		if(w[l][d] > sh[l][d]){
			w[l][d] = w[d][l] = v[i].fi;
			total += v[i].fi;
		}
	}

	if(!ok)
		printf("-1\n");
	else
		printf("%lld\n", total);
	return 0;
}

Measured memory_bytes: 3064
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let mut n: u64 = itr.next().unwrap().parse().unwrap();
    let mut k: u64 = itr.next().unwrap().parse().unwrap();
    if n > k {
        std::mem::swap(&mut n, &mut k);
    }
    if n <= 1 {
        if k == 1 {
            println!("{}", 1);
        } else {
            println!("{}", k - 2);
        }
    } else if n <= 2 {
        println!("{}", 0);
    } else {
        println!("{}", n * k - (n * 2 + (k - 2) * 2));
    }
}


Measured memory_bytes: 4352
//20
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int ns,nl;
int d[11][11];
int ln[11][11];
vector<int> mv,cv;
int m;
bool p[1<<20][11];

void dfs(int v,int ds,int l){
  cv.push_back(v);
  for(int i=1;i<=ns;i++){
    int ll=l|1<<ln[v][i];
    if(d[v][i]&&!p[ll][i]++){
      int cs=d[v][i];
      d[v][i]=d[i][v]=0;
      dfs(i,ds+cs,ll);
      d[v][i]=d[i][v]=cs;
    }
  }
  if(ds>m){
    m=ds;
    mv=cv;
  }
  cv.pop_back();
}

int main(){
  while(cin>>ns>>nl,ns|nl){
    fill(d[0],d[11],0);
    for(int i=0;i<nl;i++){
      int s,t,dd;
      cin>>s>>t>>dd;
      d[s][t]=d[t][s]=dd;
      ln[s][t]=ln[t][s]=i;
    }
    fill(p[0],p[(1<<20)],false);
    m=0;
    for(int i=1;i<=ns;i++){
      dfs(i,0,0);
    }
    cout<<m<<endl;
    for(int i=0;i<mv.size();i++){
      cout<<mv[i]<<((i==mv.size()-1)?'\n':' ');
    }
  }
  return 0;
}

    

Measured memory_bytes: 12476
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    string str;
    cin >> str;
    int cnt = 0, ans = str.length();
    REP(i, str.length()){
        if(str[i] == 'S'){
            cnt++;
        }else{
            if(cnt > 0){
                ans -= 2;
                cnt--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

const int MAX_L = 1000001;
const int MAX_SQRT_B = 1000001;
bool is_prime_array[MAX_L];
bool is_prime_small[MAX_SQRT_B];

bool is_prime(int n) {
	for(int i = 2; i * i <= n; i++) {
		if(n % i == 0) return false;
	}
	return n != 1;
}

vector<bool> eratosthenes(int n) {
	vector<bool> is_prime(n + 1);
	rep(i, 0, n + 1) is_prime[i] = true;
	// prime[n];

	is_prime[0] = is_prime[1] = false;
	int ans = 0;
	rep(i, 2, n + 1) {
		if(is_prime[i]) {
			// prime[ans++] = i;
			ans++;
			for(int j = 2 * i; j <= n; j += i) is_prime[j] = false;
		}
	}
	return is_prime;
}

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

	int N;
	cin >> N;

	int cnt = 0;
	vector<int> rsl;
	vector<bool> prime_a = eratosthenes(55555);
	for(int i = 6; i <= 55555; i += 5) {
		if(cnt == N) {
			rep(j, 0, N - 1) cout << rsl[j] << " ";
			cout << rsl[N - 1] << endl;
			return 0;
		}
		if(prime_a[i]) {
			rsl.push_back(i);
			cnt++;
		}
	}
}


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

int main(){
  int h, w;
  cin >> h >> w;
  
  vector<string> str(h);
  
  for(int i = 0; i < w+2; i++)//1行目
  	cout << "#";
  for(int i = 0; i < h; i++){//最後から二番目まで
    cin >> str.at(i);
    cout << endl << "#" << str.at(i) << "#";
  }
  cout << endl;
  for(int i = 0; i < w+2; i++)
    cout << "#";
  cout << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<long long, long long>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

//////////////////////////////////

vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;
	
	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i-1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

void dfs(int from) {
	int c = 1;
	for (auto t : tree[from]) {
		c = c != color[from] ? c : c + 1;
		color[t] = c;
		colorMap[make_pair(from, t)] = c;
		m = max(c, m);
		dfs(t);
		c++;
	}
}

int cnt;
int target;
void calc(int c) {
	cnt -= (target / c);
	target %= c;
}

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

	int ans = 0;
	for (char i = '0'; i <= '9'; ++i) {
		for (char j = '0'; j <= '9'; ++j) {
			for (char k = '0'; k <= '9'; ++k) {
				if (i == '0' && j == '2' && k == '4') {
					int aaa = 1;
				}
				bool b[3] = {0,0,0};
				for (int l = 0; l < n; ++l) {
					if (b[0] && b[1]) {
						if (k == s[l]) {
							b[2] = true;
							ans++;
							break;
						}
					}
					else if (b[0]) {
						if (j == s[l])b[1] = true;
					}
					else {
						if (i == s[l])b[0] = true;
					}
				}
			}
		}
	}

	cout << ans << endl;	
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

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

using namespace std;

typedef long long int lli;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    REP (i, 0, N) cin >> A[i];
    lli ans = pow(3, N);
    int cnt = 0;
    REP (i, 0, N) {
        if (A[i] % 2 == 0) cnt++;
    }
    cout << ans - (lli)pow(2, cnt) << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;

const int MAXH = 21;
const int MAXW = 21;
const int MAXT = 103;
const int INF = 1<<28;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
int H, W;
int D;
int G[MAXH][MAXW][4];
int S[MAXH][MAXW];
bool dp[MAXT][MAXH][MAXW][4];

pair<int,int> getPair() {
  string s;
  cin >> s;
  replace(s.begin(), s.end(), '-', ' ');
  stringstream ss(s);
  char h;
  int v;
  ss >> h >> v;
  return make_pair(h-'a', v-1);
}

int main() {
  while(cin >> H >> W && (H|W)) {
    cin >> D;
    {
      fill(S[0], S[MAXH], 0);
      int ns;
      cin >> ns;
      while(ns--) {
        pair<int,int> p = getPair();
        cin >> S[p.first][p.second];
      }
    }
    {
      fill(G[0][0], G[MAXH][0], D);
      int nc;
      cin >> nc;
      while(nc--) {
        pair<int,int> p1 = getPair();
        pair<int,int> p2 = getPair();
        int tx = p2.second - p1.second;
        int ty = p2.first - p1.first;
        for(int i = 0; i < 4; ++i) {
          if(dx[i] == tx && dy[i] == ty) {
            G[p1.first][p1.second][i] = INF;
            G[p2.first][p2.second][(i+2)%4] = INF;
            break;
          }
        }
      }
    }
    {
      int nj;
      cin >> nj;
      while(nj--) {
        pair<int,int> p1 = getPair();
        pair<int,int> p2 = getPair();
        int d;
        cin >> d;
        int tx = p2.second - p1.second;
        int ty = p2.first - p1.first;
        for(int i = 0; i < 4; ++i) {
          if(dx[i] == tx && dy[i] == ty) {
            G[p1.first][p1.second][i] = D+d;
            G[p2.first][p2.second][(i+2)%4] = D+d;
            break;
          }
        }
      }
    }
    pair<int,int> src = getPair();
    pair<int,int> dst = getPair();

    fill(dp[0][0][0], dp[MAXT][0][0], false);
    dp[0][src.first][src.second][0] = true;
    for(int t = 0; t < MAXT; ++t) {
      for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
          for(int d = 0; d < 4; ++d) {
            if(!dp[t][i][j][d]) continue;
            for(int k = 0; k < 4; ++k) {
              if(k == (d+2)%4) continue;
              if(G[i][j][k] == INF) continue;
              int ni = i + dy[k];
              int nj = j + dx[k];
              if(nj < 0 || nj >= W) continue;
              if(ni < 0 || ni >= H) continue;
              int nt = t + G[i][j][k];
              if(nt >= MAXT) continue;
              if(S[ni][nj]) {
                int a = (nt / S[ni][nj]) % 2;
                if(a == k % 2) continue;
              }
              dp[nt][ni][nj][k] = true;
            }
          }
        }
      }
    }

    try {
      for(int t = 0; t < MAXT; ++t) {
        for(int d = 0; d < 4; ++d) {
          if(dp[t][dst.first][dst.second][d]) {
            cout << t << endl;
            throw 0;
          }
        }
      }
    } catch(...) {}
  }
  return 0;
}

Measured memory_bytes: 1472
s=list(input())
ans=0
count=0
for i in range(len(s)):
    if s[i]=='A'or s[i]=='T' or s[i]=='C' or s[i]=='G':
        for j in range(i,len(s)):
            if s[j]=='A' or s[j]=='T' or s[j]=='C' or s[j]=='G':
                count+=1
                if j==len(s)-1:
                    if count>ans:
                        ans=count
                        count=0
                        break
                    else:
                        count=0
                        break
            else:
                if count>ans:
                    ans=count
                    count=0
                    break
                else:
                    count=0
                    break
print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
#define intt long long

int main() {
	intt N, M; std::cin >> N >> M;
	std::vector<intt> a(N);
	std::vector<intt> b(N);
	std::vector<intt> c(M);
	std::vector<intt> d(M);
	for (intt i = 0; i < N; ++i)
		std::cin >> a[i] >> b[i];
	for (intt i = 0; i < M; ++i)
		std::cin >> c[i] >> d[i];
	for (intt i = 0; i < N; ++i) {
		intt dmin = 10000000000000;
		intt p = 0;
		for (intt j = 0; j < M; ++j) {
			if (dmin > std::abs(a[i] - c[j]) + std::abs(b[i] - d[j]))
				p = j + 1;
			dmin = std::min(dmin, std::abs(a[i] - c[j]) + std::abs(b[i] - d[j]));
		}
		std::cout << p << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char num[3];
  cin >> num;
  if(num[0] == '7' || num[1] == '7' || num[2] == '7'){
  cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3672
n = gets.to_i
r0 = gets.to_i
min = r0
max = r0
diff = - 10**9
(n - 1).times do
  r = gets.to_i
  if min >= r
    diff = [diff, r - min].max
    min = r
    max = r
  elsif max < r
    diff = [diff, r - min].max
    max = r
  end
end
puts diff



Measured memory_bytes: 6880
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

int main() {
  int X; cin >> X;
  int imax = 1;
  for(int b = 1; b < 40; b++) {
    for(int p = 2; p < 40; p++) {
      int a = pow(b,p);
      if(a <= X)
        imax = max(imax, a);
    }
  }
  cout << imax << endl;
}


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

int f(int n) {
    if (n % 2 == 0) {
        return n / 2;
    } else {
        return 3 * n + 1;
    }
}

void solve() {
    int s;
    cin >> s;

    unordered_map<int, int> a;
    a[s] = 1;
    int ans = 1;
    while (true) {
        s = f(s);
        ans++;
        if (a.count(s)) break;
        a[s] = 1;
    }
    print(ans);

}

signed main() {
    solve();
}


Measured memory_bytes: 256
'use strict'

function Main(input){
    let s = input.trim();
    let b = parseInt(s.slice(0,2));
    let a = parseInt(s.slice(2,4));

    let yymm,mmyy;
    if( 1 <= b && b <= 12 ) mmyy = true;
    if( 1 <= a && a <= 12 ) yymm = true;

    if(mmyy && yymm){
        console.log('AMBIGUOUS');
    }else if(!mmyy && !yymm){
        console.log('NA');
    }else if(mmyy){
        console.log('MMYY');
    }else{
        console.log('YYMM');
    }

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
while True:
    x,y=map(int,input().split())
    if x<=y:
        x,y=y,x
    if x==y==0:
        break
    z=0
    while True:
        if y==0:
            break
        x=x%y
        x,y=y,x
        z+=1
    print(x,z)


Measured memory_bytes: 5604
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);
    const sc = arg.slice(1, M + 1).map(n=>n.split(" "));
    
    let answer = new Array(N).fill("x");
    
    if(N === 1 && M === 0) {
        console.log(0);
        return;
    }

    for(let i in sc) {
        let digit  = parseInt(sc[i][0]);
        let number = sc[i][1];
        
        // console.log("answer:" + answer);
        // console.log("a:" + answer[digit - 1]);
        // console.log(answer[digit - 1] !== "x");
        
        // すでに他の数字で確保されているのはNG
        if(answer[digit - 1] !== number && answer[digit - 1] !== "x") {
            console.log(-1);
            return;
        }

        answer[digit - 1] = number;
    }
    
    // 最小を考える
    for(let i in answer) {
        if(answer[answer.length - i] === "x") {
            answer[answer.length - i] = 0;
        }
    }

    
    if(answer[0] === "x") {
        answer[0] = 1;
    }

    console.log(String(parseInt(answer.join(""))).length === N ? answer.join("") : -1);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<cstdio>
using namespace std;
long long m,v[100001];
long long ans=1,cnt=0,p=0,k=1;
int main()
{
//	freopen("robot.in","r",stdin);
//	freopen("robot.out","w",stdout);
	scanf("%lld",&m);
	for(int i=1;i<=m;i++)
	{
	scanf("%lld",&v[i]);
	int z=(v[i-1]+1)/2-(i-1);
	while(z<p)
	{
		ans=ans*cnt%1000000007;
		cnt--;
		p--;
		k++;
	}
	cnt++;
	}
	for(;k<=m;k++)
	ans=ans*(cnt--)%1000000007;
	printf("%lld",ans);
//	fclose(stdin);
//	fclose(stdout);
}

Measured memory_bytes: 896
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front
#define ins insert

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
unsigned XorShift(void){static unsigned x = 123456789;static unsigned y = 362436069;static unsigned z = 521288629;static unsigned w = 88675123;unsigned t;t = x ^ (x << 11);x = y; y = z; z = w;return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int a,b,c;

main(){
	cin>>a>>b>>c;
	dump(a+b+c-max({a,b,c}));
}


Measured memory_bytes: 256
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end
h = gets_i

total = 0
if h == 1
  total = 1
else
  i = 0
  while h != 0
    h = h/2
    total += 2 ** i
    i += 1
  end
end

puts total

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

#define int long long

vector<bool>flag(1e9+2,false);

signed main(void){
    int n; cin >> n;
    for(int i=0;i<n;i++){
        int a; cin >>a;
        if(flag[a]==false){
            flag[a] = true;
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 122368
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
	char s[101], p[101];
	cin >> s;
	cin >> p;

	int sl, pl;
	sl = strlen(s);
	pl = strlen(p);

	bool suc = false;
	for (int i = 0; i < sl; i++) {
		for (int j = 0; j < pl; j++) {
			if (s[(i + j) % sl] != p[j]) break;
			if (j == pl-1) suc = true;
		}
		if (suc) break;
	}

	cout << (suc ? "Yes" : "No") << endl;

	return 0;
}


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


int main() {
  int n,m;
  cin >>n>>m;
  vector<int> s(m);
  vector<int> c(m);
  for(int i=0;i<m;i++)cin>>s[i] >>c[i];
  for(int i=0;i<m;i++){ 
    for(int j=0;j<m;j++){
   if(i !=j&& s[i] ==s[j] && c[i] != c[j] ) {
     cout <<-1 <<endl; 
   return 0;
   }
  }
  }

  if(n==1){
   if(m==0) cout <<0 <<endl;
    else cout <<c[0] <<endl;
  }
  else if(n ==2){
    int sum =0;
	for(int i=0;i<m;i++){
      if(s[i]==1 && c[i] ==0){
        cout <<-1 <<endl; 
      return 0;
      }
 else 	if(s[i] ==1  && sum/10 != c[i]) sum += c[i]*10;
      else if(s[i] ==2 && sum-(sum/10)*10 != c[i]) sum += c[i];
    }
    if(sum /10 ==0) cout <<sum +10 <<endl;
  else  cout <<sum <<endl;
  }
  else if(n==3){
   int sum =0;
    for(int i=0;i<m;i++){
      if(s[i]==1 && c[i] ==0){
       cout <<-1 <<endl;
      return 0;
      }
	else  if(s[i] ==1 && sum/100 != c[i]) sum += c[i]* 100;
      else if(s[i] ==2 &&(sum-(sum/100)*100)/10 != c[i]) sum += c[i]*10;
      else if(s[i] ==3 && sum-(sum/10)*10 != c[i] )sum += c[i];
    }
    if(sum /100 ==0) cout << sum+100 <<endl;
  else   cout <<sum <<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
#define fst first
#define snd second
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}
inline int Log2(ll x) {int k; for(k=0; x>0; ++k) x>>=1; return k;} // number of binary digits
template<typename T> inline int count_between(vector<T>& a, T l, T r) {
  return lower_bound(all(a), r) - lower_bound(all(a), l); // [l, r)
}
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;


struct V2d {
  ld x, y;
  V2d(ld x=0, ld y=0): x(x), y(y) {}
  V2d& operator+=(const V2d& v) { x += v.x; y += v.y; return *this;}
  V2d operator+(const V2d& v) const { return V2d(*this) += v;}
  V2d& operator-=(const V2d& v) { x -= v.x; y -= v.y; return *this;}
  V2d operator-(const V2d& v) const { return V2d(*this) -= v;}
  V2d& operator*=(ld s) { x *= s; y *= s; return *this;}
  V2d operator*(ld s) const { return V2d(*this) *= s;}
  V2d& operator/=(ld s) { x /= s; y /= s; return *this;}
  V2d operator/(ld s) const { return V2d(*this) /= s;}
  ld dot(const V2d& v) const { return x*v.x + y*v.y;}
  ld cross(const V2d& v) const { return x*v.y - v.x*y;}
  ld norm2() const { return x*x + y*y;}
  ld norm() const { return sqrt(norm2());}
  V2d rotate90() const { return V2d(y, -x);}
  int ort() const { // orthant
    if (abs(x) < EPS && abs(y) < EPS) return 0;
    if (y > 0) return x>0 ? 1 : 2;
    else return x>0 ? 4 : 3;
  }
  bool operator<(const V2d& v) const {
    int o = ort(), vo = v.ort();
    if (o != vo) return o < vo;
    return cross(v) > 0;
  }
};
istream& operator>>(istream& is, V2d& v) {
  is >> v.x >> v.y; return is;
}
ostream& operator<<(ostream& os, const V2d& v) {
  os << "(" << v.x << ", " << v.y << ")"; return os;
}


int main() {
  int n; cin >> n;
  vector<V2d> p(n);

  rep(i, n) cin >> p[i];
  sort(all(p));
  
  ld ans = 0;
  rep(i, n) {
    V2d now;
    rep(j, n) {
      now += p[(i+j)%n];
      chmax(ans, now.norm2());
    }
  }

  cout << setprecision(12);
  cout << sqrt(ans) << endl;
  return 0;
}


Measured memory_bytes: 256
a = int(input())

if 400 <= a and a <= 599:
    print(8)
elif 600 <= a and a <= 799:
    print(7)
elif 800 <= a and a <= 999:
    print(6)
elif 1000 <= a and a <= 1199:
    print(5)
elif 1200 <= a and a <= 1399:
    print(4)
elif 1400 <= a and a <= 1599:
    print(3)
elif 1600 <= a and a <= 1799:
    print(2)
elif 1800 <= a and a <= 1999:
    print(1)

Measured memory_bytes: 9192
//import java.lang.Math;
import java.util.*;
//import java.util.ListIterator;
//import java.util.Iterator;
//import java.util.LinkedList;


class Main{
	
	public static void main(String[] arg){
		
	

		int a=0,b=0;
		Scanner sc= new Scanner(System.in);
		List<Integer> list =new ArrayList<Integer>();
		int m=sc.nextInt();
		int[] str=new int[m];
		for(int i=0;i<m;i++){
			str[i]=sc.nextInt();
			list.add(new Integer(str[i]));
		}
		int n=sc.nextInt();
		for(int j=0;j<n;j++){
			int d=sc.nextInt();
			switch(d){
			case 0:
				a=sc.nextInt();
			    b=sc.nextInt();
			   
				List<Integer> l2=list.subList(a, b);
				int c=Collections.min(l2);
				System.out.println(c);
				break;
			case 1:
				
				a=sc.nextInt();
			    b=sc.nextInt();
					List<Integer> l3=list.subList(a, b);
				int q=Collections.max(l3);
				System.out.println(q);
				break;
			}
		}
	}}


Measured memory_bytes: 33416
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct SegTree {
    int n;
    vll dat;

    SegTree(int _n) {
        int m = 1;
        while(m < _n) m *= 2;
        n = m;
        dat = vll(2 * n - 1, (1ll << 31) - 1);  // Need to check
    }

    void update(int i, ll x) {
        i += n - 1;
        dat[i] = x; // Need to check
        while(i > 0) {
            i = (i - 1) / 2;
            dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);   // Need to check
        }
    }

    ll query_sub(int a, int b, int k, int l, int r) {
        if(r <= a || b <= l) return INFL;    // Need to check
        if(a <= l && r <= b) return dat[k];
        else {
            ll vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            ll vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr); // Need to check
        }
    }

    ll query(int a, int b) {
        return query_sub(a, b, 0, 0, n);   // query for [a, b)
    }
};

void solve() {
    ll n, q;
    cin >> n >> q;
    SegTree st(n);
    vll ans;
    for(ll i = 0; i < q; i++) {
        ll c, x, y;
        cin >> c >> x >> y;
        if(c == 0) {
            st.update(x, y);
        }
        else {
            ans.push_back(st.query(x, y + 1));
        }
    }
    for(auto i : ans) cout << i << endl;
    return;
}

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


Measured memory_bytes: 5576
# D
N = int(input())

res_dict = dict()
for i0 in "ACGT":
    for i1 in "ACGT":
        for i2 in "ACGT":
            s = i0+i1+i2
            if s in ["AGC", "ACG", "GAC"]:
                res_dict[s] = [0, 0, 0, 0] + [0]*(N-3)
            else:
                res_dict[s] = [0, 0, 0, 1] + [0]*(N-3)

for i in range(3, N):
    for k in res_dict.keys():
        for add in "ACGT":
            s = k + add
            if k[1:] + add in ["AGC", "ACG", "GAC"] or k[:2] + add == "AGC" or k[0] + k[2] + add == "AGC":
                pass
            else:
                res_dict[s[1:]][i+1] += res_dict[k][i]
                
print(sum([res_dict[s][N] for s in res_dict.keys()]) % (10**9+7))

Measured memory_bytes: 3316
//这道题的做法很巧妙 
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 20005
#define LL long long
int n;
LL a[MAXN],b[MAXN];
int p[MAXN];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		p[x]=i;
	}
	for(int i=1;i<n;i++)
		printf("%d ",MAXN*i);
	printf("%d\n",MAXN*n);
	for(int i=1;i<n;i++)
		printf("%d ",MAXN*(n+1-i)+p[i]);
	printf("%d\n",MAXN+p[n]);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

long long int n,m;
long long int a[2001]={},b[2001]={},c[2001]={};
long long int d[2001]={};
bool inf = false;
long long int INF = 1000000001;
long long int INFLL = (long long int)INF * INF;
bool dame=false;
int main(){
        cin >> n >> m;
        for(long long int i=0; i<m; i++) {
                cin >> a[i] >>b[i]>>c[i];
                a[i]--;b[i]--;
        }
        for(int i=0; i<n; i++) d[i] = -INFLL;
        d[0]=0;
        for(int k=0; k<=2*n; k++) {
                for(int i=0; i<m; i++) {
                        if(d[a[i]] != -INFLL && d[b[i]]<d[a[i]]+c[i]) {
                                d[b[i]] = d[a[i]] + c[i];
                                if(k==2*n && b[i]==n-1)dame=true;
                        }
                }
        }
    if(dame)cout<<"inf"<<endl;
    else cout<<d[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main() 
{
	ll n=0;
	bool flag=false;
	cin>>n;
	vector<ll> s(n);
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
	}
	sort(s.begin(),s.end());
	for(int i=0;i<n;i++)
	{
		if(s[i]==s[i+1])
		{
			flag=true;
		}
	}
	if(flag)
	{
		cout<<"NO"<<endl;
	}
	else
	{
		cout<<"YES"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Linq;
 
namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            int count;
            while((count = int.Parse(Console.ReadLine())) != 0) {
                var value = new int[7];
                foreach(var i in Enumerable.Range(0, count)) {
                    int age = int.Parse(Console.ReadLine());
                    if(age >= 70) {
                        age = 60;
                    }
                    ++value[age / 10];
                }
                for(int i = 0; i < value.Length; ++i) {
                    Console.WriteLine(value[i]);
                }
            }
        }
    }
}

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

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  int ans = -1;
  bool flag = true;
  while (flag) {
    ans++;
    for (int i = 0; i < N; i++) {
      if (a[i] & 1) {
        flag = false;
        break;
      }
      a[i] /= 2;
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,cnt=0;
  cin >> N ;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
    if(!(p.at(i)==i+1)) cnt++;
  }
  
  if(cnt<=2) cout << "YES" <<endl;
  else cout <<"NO" <<endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
H = [int(x) for x in input().split()]
 
def main(N,K,H):
    dp = [0]*N
    for i in range(1,N):
        L = [dp[j]+abs(H[i]-H[j]) for j in range(max(0,i-K),i)]
        dp[i] = min(L)
    print(dp[-1])
main(N,K,H)
#自分のコードがTLEになるので、他の人が書いたコードでAC出来るのか確認。

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

#define fr first
#define sc second
#define mk make_pair
#define pb push_back

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector <ll> vll;
typedef vector <int> vii;
typedef vector <pll> vpll;
typedef vector <pii> vpii;
const int N = 2e5 + 5;
const int inf = 1e9 + 7;

int a[N], b[N], ans[N];

void solve() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		b[i] = a[i];
		b[i] ^= b[i - 1];
	}
	for (int i = 1; i <= n; i ++) {
		ans[i] = b[n] ^ a[i];
	}
	for (int i = 1; i <= n; i ++) 
		cout << ans[i] << " ";
	cout << endl;
}                              

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









Measured memory_bytes: 5908
n, x, y = map(int, input().split())
ans = [0]*n
x, y = min(x, y), max(x, y)
 
for i in range(1, n):
    for j in range(i+1, n+1):
        # calculate dist(i, j)
        dist = j - i
        dist = min(dist, abs(j - y) + abs(x - i) + 1)
        dist = min(dist, abs(j - x) + abs(y - i) + 1)
        ans[dist] += 1
print("\n".join(list(map(str, ans[1:]))))

Measured memory_bytes: 46044
class Dice():
    def __init__(self, dice_labels):
        self.label = {
            'top': dice_labels[0],
            'south': dice_labels[1],
            'east': dice_labels[2],
            'west': dice_labels[3],
            'north': dice_labels[4],
            'bottom': dice_labels[5]
        }

    def roll(self, str_direction):
        if str_direction == 'E':
            self.__roll_to_east()
        elif str_direction == 'W':
            self.__roll_to_west()
        elif str_direction == 'S':
            self.__roll_to_south()
        elif str_direction == 'N':
            self.__roll_to_north()

    def turn(self, str_direction):
        if str_direction == 'L':
            self.__turn_left()
        elif str_direction == 'R':
            self.__turn_right()

    def __roll_to_east(self):
        self.label['top'], self.label['east'], self.label['west'], self.label['bottom'] = (self.label['west'], self.label['top'], self.label['bottom'], self.label['east'])

    def __roll_to_west(self):
        self.label['top'], self.label['east'], self.label['west'], self.label['bottom'] = (self.label['east'], self.label['bottom'], self.label['top'], self.label['west'])

    def __roll_to_south(self):
        self.label['top'], self.label['south'], self.label['north'], self.label['bottom'] = (self.label['north'], self.label['top'], self.label['bottom'], self.label['south'])

    def __roll_to_north(self):
        self.label['top'], self.label['south'], self.label['north'], self.label['bottom'] = (self.label['south'], self.label['bottom'], self.label['top'], self.label['north'])

    def __turn_right(self):
        self.label['south'], self.label['east'], self.label['west'], self.label['north'] = (self.label['east'], self.label['north'], self.label['south'], self.label['west'])

    def __turn_left(self):
        self.label['south'], self.label['east'], self.label['west'], self.label['north'] = (self.label['west'], self.label['south'], self.label['north'], self.label['east'])

def check_same_dice(dice1, dice2):
    for direction in ['top', 'bottom', 'east', 'west', 'south', 'north']:
        if dice1.label[direction] != dice2.label[direction]:
            return False
    return True

dice_labels1 = input().split(' ')
dice_labels2 = input().split(' ')
dice1 = Dice(dice_labels1)
dice2 = Dice(dice_labels2)
same_pattern_list = []

for i in range(0, 4):
    for j in range(0, 4):
        for k in range(0, 4):
            dice2.roll('E')
            same_pattern_list.append(check_same_dice(dice1, dice2))
        dice2.roll('N')
        same_pattern_list.append(check_same_dice(dice1, dice2))
    dice2.turn('R')
    same_pattern_list.append(check_same_dice(dice1, dice2))

if True in same_pattern_list:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 5584
#include<bits/stdc++.h>
using namespace std;
main(){
int i,j,k,l,n,p;
while(cin>>p){
        int x[p];
n=0;
for(i=0;i<p;i++){cin>>x[i]; n+=x[i]; }
sort(x,x+p);
n-=x[p-1];
n+=(x[p-1]/2);
cout<<n<<endl;
}
return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

bool field[101][101];

signed main()
{
	int A, B;
	cin >> A >> B;
	cout << ((A - 1) * (B - 1)) << endl;
}



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

int main() {
	long long n,i;
	cin >> n;
	vector<long long> l(n+1);
	l[0]=2; l[1]=1;
	for(i=2; i<=n; i++){
		l[i]=l[i-2]+l[i-1];
	}
	cout << l[n];
}

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

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  long long int h[100005];
  int c[100005];
  for(int i=0;i<n;i++){
    cin>>h[i];
    c[i]=0;
  }
  
  int j=0;
  for(int i=0;i<n-1;i++){
    if(h[i]>=h[i+1]){
      c[j]++;
    }else{
      j++;
    }
  }
  sort(c,c+j+1);
  cout<<c[j];
}

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

int main(){
    string s;
    cin >> s;
    while(true){
        s.pop_back();
        s.pop_back();
        if(s!=""){
            bool ok=true;
            for(int i=0;i<s.size()/2;i++){
                if(s[i]!=s[s.size()/2+i])ok=false;
            }
            if(ok){cout << s.size() << endl;break;}
        }
        else{break;}
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int a[1000000];
int n;

int binary_search(int key){

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

}


int main() {
    int i,key,q,sum=0;

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

    cin >> q;
    for(i=0;i<q;i++){
        cin >> key;
        if(binary_search(key)) sum++;
    }

    cout << sum << endl;


    return 0;

}

Measured memory_bytes: 3472