akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

use rand::Rng;


fn main() {
    input! {
        D: usize,
        C: [i64; 26],
        S: [[i64; 26]; D],
    }

    let score = |sol: &Vec<i64>| -> i64 {
        let mut sat: i64 = 0;
        let mut last = vec![0; 26];
        for (d, v) in sol.iter().enumerate() {
            let j: usize = (v - 1) as usize;
            last[j] = d + 1;
            for i in 0..26 {
                sat -= (d + 1 - last[i]) as i64 * C[i];
            }
            sat += S[d][j];
        }

        return sat;
    };

    let mut ans:Vec<i64> = vec![];
    let mut last = vec![0; 26];
    for d in 0..D {
        let mut ma = 0;
        let mut mai = 0;
        for j in 0..26 {
            let a = (d + 1 - last[j]) as i64 * C[j] + S[d][j];
            if a > ma {
                ma = a;
                mai = j;
            }
        }
        last[mai] = d + 1;
        ans.push((mai+1) as i64);
    }

    let mut rng = rand::thread_rng();
    let mut s = score(&ans);
    for _ in 0..350000 {
        let c = rng.gen_range(1, 27);
        let d = rng.gen_range(0, D);
        let b = ans[d];
        ans[d] = c;
        let ss = score(&ans);
        if ss > s{
            // dbg!(ss);
            s = ss;
        }else{
            ans[d] = b;
        }
    }

    for c in ans {
        println!("{}", c);
    }
}


Measured memory_bytes: 2756
#include<stdio.h>
#include<string.h>
int main(){
    char str[101];
    scanf("%s",str);
    int l = strlen(str);
    int c = 0;
    int i;
    for(i=0;i<l/2;i++){
        if(str[i] != str[l-1-i]){
            c = c+1;
        }
    }
    printf("%d",c);
    return 0;
}

Measured memory_bytes: 128
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

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

  int N;
  cin >> N;
  int D = N % 10;
  N /= 10;
  int C = N % 10;
  N /= 10;
  int B = N % 10;
  N /= 10;
  int A = N % 10;

  if (A + B + C + D == 7) printf("%d+%d+%d+%d=7\n", A, B, C, D);
  else if (A - B + C + D == 7) printf("%d-%d+%d+%d=7\n", A, B, C, D);
  else if (A + B - C + D == 7) printf("%d+%d-%d+%d=7\n", A, B, C, D);
  else if (A - B - C + D == 7) printf("%d-%d-%d+%d=7\n", A, B, C, D);
  else if (A + B + C - D == 7) printf("%d+%d+%d-%d=7\n", A, B, C, D);
  else if (A - B + C - D == 7) printf("%d-%d+%d-%d=7\n", A, B, C, D);
  else if (A + B - C - D == 7) printf("%d+%d-%d-%d=7\n", A, B, C, D);
  else if (A - B - C - D == 7) printf("%d-%d-%d-%d=7\n", A, B, C, D);
  return 0;
}


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

int main() {
 
	long n;
	
	cin >> n;
	
    long ans = -1;
    long i, j;
    for (i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            j = n / i; 
            if (ans != -1) {
                if (ans > i - 1 + j - 1) {
                    ans = i - 1 + j - 1;
                }
            } else {
                ans = i - 1 + j - 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	int N, T;
	cin >> N >> T;
	vector<int> c(N), t(N);
	int min_cost = INF;
	int count = 0;
	for (int i = 0; i < N; i++) {
		cin >> c[i] >> t[i];
		if (t[i] <= T) {
			if (c[i] < min_cost) {
				min_cost = c[i];
				count++;
			}
		}
	}
	if (count == 0) {
		cout << "TLE";
	}
	else {
		cout << min_cost;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#define int long long
using namespace std;

typedef pair<int, int> Pii;

void readline(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readline(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}

signed main(){

    int D, N;
    cin >> D >> N;

    int ans = 1;
    for(int i = 0; i < D; i++){
        ans *= 100;
    }

    if(N == 100){
        cout << 101 * ans;
    }else{
        cout << N * ans;
    }

    return 0;
}

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

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

using namespace std;

int main(void) {
	vector<pair<int, int> > in;
	while(1) {
		int H, W;
		cin >> H >> W;
		if(H == 0 && W == 0) break;
		in.push_back(make_pair(H, W));
	}
	int start_key = 0;
	int key = 0;
	char field[2] = {'#', '.'};
	REP(i, in.size()) {
		REP(j, in[i].first) {
			key = start_key;
			REP(k, in[i].second) {
				cout << field[key];
				key = 1 - key;
			}
			cout << endl;
			start_key = 1 - start_key;
		}
		cout << endl;
		start_key = key = 0;
	}

	return 0;
}


Measured memory_bytes: 3092
n = gets.to_i
a = gets.split.map(&:to_i).to_a
q = gets.to_i

dict = [0] * (10**5+1)
ans = a.sum

a.each do |a|
  dict[a] += 1
end

q.times do
  b, c = gets.split.map(&:to_i)
  s = dict[b]
  dict[b] = 0
  ans += c*s
  ans -= b*s
  dict[c] += s
  puts ans
end


Measured memory_bytes: 22016
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<set>
#include<iomanip>

using namespace std;

int main(){
	int n, m, ans = 0;
	cin >> n >> m;
	vector<pair<int, int>> a(m);
	vector<vector<int>> b(n + 1);
	for(int i = 0; i < m; i++){
		cin >> a[i].first >> a[i].second;
		b[a[i].first].push_back(a[i].second);
	}
	for(int i = 1; i <= n; i++){
		sort(b[i].begin(), b[i].end());
	}
	for(auto&& i : a){
		int x = i.first, y = i.second;
		cout << setfill('0') << setw(6) << x << setfill('0') << setw(6) << (lower_bound(b[x].begin(), b[x].end(), y) - b[x].begin() + 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 7808
#include <iostream>
#include <vector>
using namespace std;
void A(void);
void B(void);
void C(void);
void D(void);

int main(void){
    B();
}

void B(void){
    long long int x,sum;
    cin>>x;
    int i;
    sum=100;
    for(i=0;sum<x;++i){
        sum+=sum/100;
    }
    cout<<i<<endl;
}

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

int main(){
  int a,b,c;
  cin>>a>>b;
  c=a+b;
  if(c<24) {
    cout<<c<<endl;
  }
  if(c>=24) {
    while(c>=24){
      c=c-24;
    }
    cout<<c<<endl;
    
  }
  
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int ans[2000][2000];
int num[2000][2000];

int main() {
    int K = 1;
    while (true) {
        K++;
        if (K*(K-1)+1 >= 1000) {
            bool ok = true;
            for (int i = 2; i <= K-2; i++) {
                if ((K-1)%i == 0) {
                    ok = false;
                    break;
                }
            }
            if (ok) break;
        }
    }
    int N = K*(K-1)+1;
    for (int i = 0; i < K; i++) ans[0][i] = i+1;
    for (int i = 1; i < N; i++) ans[i][0] = (i-1)/(K-1)+1;
    for (int i = 0; i < K-1; i++) {
        for (int j = 0; j < K-1; j++) {
            num[i][j] = K+i*(K-1)+j+1;
        }
    }
    rep(j,K-1) rep(k,K-1) {
        ans[1+j][1+k] = num[j][k];
    }
    for (int i = 0; i < K-1; i++) {
        for (int j = 0; j < K-1; j++) {
            int pos = j;
            for (int k = 0; k < K-1; k++) {
                ans[K+i*(K-1)+j][1+k] = num[k][pos];
                pos = (pos+i)%(K-1);
            }
        }
    }

    cout << N << " " << K << endl;
    rep(i,N) {
        rep(j,K) {
            if (j != K-1) cout << ans[i][j] << " ";
            else cout << ans[i][j] << endl;
        }
    }
}

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

using namespace std;

#define N 100
#define Na 101

bool harray[Na][Na];

int main(void) {
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      harray[i][j] = false;

  int n;
  int maxh = 0;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int h;
    cin >> h;
    maxh = max(h, maxh);

    for(int j = 0; j < h; j++) {
      harray[i][j] = true;
    }
  }

  int pspanc = 0;
  for (int j = 0; j < maxh; j++) {
    bool prev = false;
    for (int i = 0; i < n; i++) {
      if (harray[i][j] == true && prev == false)
      {
        pspanc++;
      }
      prev = harray[i][j];
    }
  }

  cout << pspanc << endl;

  return 0;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<double> P(N);
    for(int i=0;i<N;i++) cin >> P[i];
    vector<double> S(N+1);
    for(int i=0;i<N;i++){
        S[i+1] = S[i] + (1+P[i])/2;
    }
    double ans = 0;

    for(int i=K;i<=N;i++){
        ans = max(ans, S[i]-S[i-K]);
    }
    cout << fixed << setprecision(10) << ans << endl;
}

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

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

int main() {
    int INF = 100000007;
    int n,m;cin>>n>>m;
    
    int x;cin>>x;
    int c[n],a[n][m];
    
    rep(i,n){
        cin>>c[i];
        rep(j,m)cin>>a[i][j];
    }
    
    int ans = INF;
    
    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<n); ++bit)
    {
      int cc = 0;

      vector<int>b(m,0);
        /* bit で表される集合の処理を書く */
        /* きちんとできていることを確認してみる */
        // bit の表す集合を求める
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
            cc += c[i];
            rep(j,m)b[j]+=a[i][j];
            }
        }
        sort(b.begin(),b.end());
        if(b[0] >= x)ans = min(ans, cc);
    }
    if(ans == INF) ans = -1;
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3652
N = int(input())
A = [int(a) for a in input().split()] + [0] * 2
X = [[-10**10] * (N+1) for _ in range(N+1)]
X[A[0]][A[1]] = 0
ans = 0
ma = 0
MA = [-5] * (N+1)
MA[A[0]] = MA[A[1]] = 0
for i in range(N):
    B = A[i*3+2:i*3+5]
    cnt = len(set(B))
    if cnt == 1:
        ans += 1
    elif cnt == 2:
        a1 = B[0]^B[1]^B[2]
        a2 = (sum(B) - a1) // 2
        X[a1], X[a1][a2], X[a2][a2] = [max(X[a2][j] + 1, X[j][a2] + 1, MA[j]) for j in range(N+1)], max(ma, X[a2][a2] + 1), max(ma, X[a1][a1] + 1)
        X[a2] = [max(x, m) for x, m in zip(X[a2], MA)]
        MA = [max(m, x1, x2) for m, x1, x2 in zip(MA, X[a1], X[a2])]
        MA[a1] = max(MA[a1], max(X[a1]))
        MA[a2] = max(MA[a2], X[a1][a2], X[a2][a2])
        ma = max(ma, MA[a1], MA[a2])
    else:
        a, b, c = B
        X[a][b], X[a][c], X[b][c] = max(ma, X[c][c] + 1), max(ma, X[b][b] + 1), max(ma, X[a][a] + 1)
        X[a] = [max(x, m) for x, m in zip(X[a], MA)]
        X[b] = [max(x, m) for x, m in zip(X[b], MA)]
        X[c] = [max(x, m) for x, m in zip(X[c], MA)]
        MA[a] = max(MA[a], max(X[a]))
        MA[b] = max(MA[b], X[a][b], max(X[b]))
        MA[c] = max(MA[c], X[a][c], X[b][c], max(X[c]))
        MA = [max(m, xa, xb, xc) for m, xa, xb, xc in zip(MA, X[a], X[b], X[c])]
        ma = max(ma, MA[a], MA[b], MA[c])

print(ans + max(ma, max(max(x) for x in X)))

Measured memory_bytes: 205564
package main

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

type edge struct {
	to    int
	value int
}

var edges [][]edge
var vertex []int
var visited []bool

func fillNumber(x int) bool {
	visited[x] = true
	for _, e := range edges[x] {
		if !visited[e.to] {
			vertex[e.to] = vertex[x] + e.value
			if !fillNumber(e.to) {
				return false
			}
		} else if vertex[e.to] != vertex[x]+e.value {
			return false
		}
	}
	return true
}

func main() {
	in := IOInitialize()
	n, m := Int(in), Int(in)

	if m == 0 || m == 1 {
		fmt.Println("Yes")
		return
	}

	edges = make([][]edge, n)
	for i := range edges {
		edges[i] = make([]edge, 0, 4)
	}

	for i := 0; i < m; i++ {
		l, r, d := Int(in)-1, Int(in)-1, Int(in)
		edges[l] = append(edges[l], edge{to: r, value: d})
		edges[r] = append(edges[r], edge{to: l, value: -d})
	}

	vertex = make([]int, n)
	visited = make([]bool, n)

	for i := range visited {
		if !visited[i] {
			if !fillNumber(i) {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}

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

func IOInitialize() *bufio.Scanner {
	t := bufio.NewScanner(os.Stdin)
	t.Split(bufio.ScanWords)
	return t
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("\t\tThere is a FALSE not to want.")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("\t\tError:Failed to convert text to int,")
	}
	return value
}

func IntArray(s *bufio.Scanner, size int) []int {
	deepArray := make([]int, size)
	for i := range deepArray {
		deepArray[i] = Int(s)
	}
	return deepArray
}

func GraphSetByEdge(s *bufio.Scanner, v int) [][]int {
	g := make([][]int, v)
	for i := range g {
		g[i] = make([]int, 0)
	}
	for xxNonUsedInLoopI := 0; xxNonUsedInLoopI < v-1; xxNonUsedInLoopI++ {
		a, b := Int(s)-1, Int(s)-1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	return g
}


Measured memory_bytes: 40064
/*
 * hoge.cpp
 *
 *  Created on: 2014/09/30
 *      Author: eiichi
 */
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<map>
using namespace std;

void draw(int H,int W){
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(i==0 || j==0 || i==H-1 || j==W-1){
				cout << "#";
			}
			else
				cout << ".";
		}
		cout << endl;
	}
}

int main(){
	int H,W;
	for(int i=0;;i++){
		cin >> H >> W;
		if(H==0 && W==0)return 0;
		draw(H,W);
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
// atcoder/abc136/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
      int x = i;
      int y = 0;
      while (x) {
        x /= 10;
        ++y;
      }
      cnt += y % 2;
    }
    cout << cnt << endl;
  }

  return 0;
}


Measured memory_bytes: 256
// OURL: https://atcoder.jp/contests/abc135/tasks/abc135_c
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool>::reference b) { return to_string(bool(b)); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res;}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  auto as = make_v<ll>(n+1);
  auto bs = make_v<ll>(n);
  REP(i,n+1) {
    cin >> as[i];
  }
  REP(i,n) {
    cin >> bs[i];
  }
  ll ans = 0;
  REP(i,n) {
    ans += min(as[i], bs[i]);
    if (as[i] < bs[i]) {
      ans += min(as[i+1], bs[i] - as[i]);
      as[i+1] -= min(as[i+1], bs[i] - as[i]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#define max(x,y)(x > y?x:y)

int main(){
	int a,b;
	scanf(" %d %d",&a,&b);
	int ans = a*b;
	ans = max(a-b,ans);
	ans = max(a+b,ans);
	printf("%d\n",ans);
	return 0;
}

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

const long long mod=998244353;
int K,n;
char s[305];
int a[305];
long long dp[305][305][2],s1[305][305][2],s2[305][305][2];
int main()
{
	int i,j,k,l;
	scanf("%s",s+1);
	scanf("%d",&K);
	K=min(K,300);
	for(i=1,n=1;s[i];i++)
	{
		if(s[i]=='1')
			a[n]++;
		else n++;
	}
	for(i=0;i<=300;i++)
		dp[i][i][1]=1;
	for(j=0;j<=300;j++)
	{
		s1[j][0][1]=dp[j][0][1];
		for(l=1;l<=j;l++)
		{
			s1[j][l][1]=(s1[j-1][l-1][1]+dp[j][l][1])%mod;
		}
	}
	for(j=0;j<=300;j++)
	{
		s2[j][0][1]=dp[j][0][1];
		for(l=1;l<=300;l++)
		{
			s2[j][l][1]=(s2[j][l-1][1]+dp[j][l][1])%mod;
		}
	}
	for(i=2;i<=n;i++)
	{
		int t=i&1;
		for(j=0;j<=300;j++)
			for(l=0;l<=300;l++)
				dp[j][l][t]=0;
		for(j=0;j<=300;j++)
			for(l=0;l<=j;l++)
			{
				dp[j][l][t]=s1[j][l][t^1];
				//for(k=j-l;k<=j;k++)
				//	dp[j][l][t]=(dp[j][l][t]+dp[k][l-j+k][t^1])%mod;
			}
		for(j=0;j<=300;j++)
			for(l=0;l<=min(300-a[i],j);l++)
			{
				dp[j][l][t]=(dp[j][l][t]+s2[j][l+a[i]][t^1]-s2[j][l][t^1]+mod)%mod;
				//for(k=1;k<=a[i];k++)
				//	dp[j][l][t]=(dp[j][l][t]+dp[j][l+k][t^1])%mod;
			}
		for(j=0;j<=300;j++)
		{
			s1[j][0][t]=dp[j][0][t];
			for(l=1;l<=j;l++)
				s1[j][l][t]=(s1[j-1][l-1][t]+dp[j][l][t])%mod;
		}
		for(j=0;j<=300;j++)
		{
			s2[j][0][t]=dp[j][0][t];
			for(l=1;l<=300;l++)
				s2[j][l][t]=(s2[j][l-1][t]+dp[j][l][t])%mod;
		}
	}
	long long ans=0;
	for(i=0;i<=K;i++)
	{
		ans=(ans+dp[i][0][n&1])%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8052
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9+5)
#define INFLL ((LL)4e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;

int main(){
	int w, x;
	cin >> w >> x;
	bool flag = false;
	for(int i=x-w+1;i<x+w;++i){
		if(flag){
			cout << " ";
		}
		cout << i;
		flag = true;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define io_optimized ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

int main(){
#define int int_fast32_t
	io_optimized
	int t,n;
	while(cin>>t)
	{
		bool c=1;
		while(t--)
		{
			cin>>n;
			if((!(n%3==0||n%5==0))&&(n%2==0))
			{
				c=0;
			}
		}
		cout<<(c?"APPROVED\n":"DENIED\n");
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e4+5;
const int INF = 1e9;
const lli MOD = 1e9+7;


vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	vi m(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

lli SUM(lli a, lli b, lli mod=MOD){
	return (a+b+mod)%mod;
}
lli PROD(lli a, lli b, lli mod=MOD){
	a%=mod; b%=mod;
	return a*b % mod;
}
int dx[4]={-1,0,0,1}, dy[4]={0,1,-1,0};

// ---- コーディングはここから！ ('-')7
struct S{
	lli w,s,v;
	bool operator < (const S &n)const{
		return ii{w+s,v}<ii{n.w+n.s,n.v};
	}
};
void solve(){
	int n; cin>>n;
	vector<S>v(n); for(auto &[a,b,c]:v)cin>>a>>b>>c;
	sort(all(v));
	// for(auto &[a,b,c]:v)cout<<a<<b<<c<<ENDL;
	vvl dp(n,vl(N,-1));
	auto f=[&](auto f, int u, lli sum)->lli{
		if(u==n or sum>=N)return 0;
		if(dp[u][sum]!=-1)return dp[u][sum];
		lli res = f(f,u+1,sum);
		if(v[u].s>=sum)res = max(res, f(f,u+1,sum+v[u].w)+v[u].v);
		return dp[u][sum]=res;
	};
	cout<<f(f,0,0)<<ENDL;

}

int main(){_
	//int t; cin>>t; fore(tt,0,t)
	solve();
}


Measured memory_bytes: 81624
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> S(H);
  for(int i=0; i<H; i++){
    cin >> S[i];
  }
  vector<vector<int>> L(H,vector<int> (W,0));
  vector<vector<int>> R(H,vector<int> (W,0));
  vector<vector<int>> U(H,vector<int> (W,0));
  vector<vector<int>> D(H,vector<int> (W,0));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(S[i][j] == '#'){
        L[i][j] = 0;
      }else{
        if(j == 0){
          L[i][j] = 1;
        }else{
          L[i][j] = L[i][j-1] + 1;
        }
      }
    }
  }
  for(int i=0; i<H; i++){
    for(int j=W-1; j>=0; j--){
      if(S[i][j] == '#'){
        R[i][j] = 0;
      }else{
        if(j == W-1){
          R[i][j] = 1;
        }else{
          R[i][j] = R[i][j+1] + 1;
        }
      }
    }
  }
  for(int i=0; i<W; i++){
    for(int j=0; j<H; j++){
      if(S[j][i] == '#'){
        U[j][i] = 0;
      }else{
        if(j == 0){
          U[j][i] = 1;
        }else{
          U[j][i] = U[j-1][i] + 1;
        }
      }
    }
  }
  for(int i=0; i<W; i++){
    for(int j=H-1; j>=0; j--){
      if(S[j][i] == '#'){
        D[j][i] = 0;
      }else{
        if(j == H-1){
          D[j][i] = 1;
        }else{
          D[j][i] = D[j+1][i] + 1;
        }
      }
    }
  }
  int ans=0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 67200
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
typedef long long ll;
using namespace __gnu_pbds;

typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double lld;

lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll i;
    for(i=0;i<b;i++)
        c*=a;
    return c;
}
ll hell=1000000007;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll dp[100005];
ll h[100005];
ll n,i,k;
ll solve(ll i)
{   if(i==(n-1))
        return 0;
    if(i>=n)
        return 1000000000000000;
    if(dp[i]!=-1)
        return dp[i];
    ll m,x;
    x=10000000000000000;
    for(m=1;m<=k;m++)
        x=min((solve(i+m)+abs(h[i]-h[i+m])),x);
    dp[i]=x;
    return x;
}

int main()
{

    cin>>n>>k;
    for(i=0;i<100005;i++)
            {dp[i]=-1;
            }

    for(i=0;i<n;i++)
        cin>>h[i];
    cout<<solve(0);
    return 0;
}






Measured memory_bytes: 6528
#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long

int main(void){
  ll n;
  cin>>n;
  vll a(n,vl(n));
  rep(i,n)rep(j,n){
    cin>>a[i][j];
  }
  vll b=a;
  rep(k,n)rep(i,n)rep(j,n){
    b[i][j]=min(b[i][j],b[i][k]+b[k][j]);
  }
    ll ans=0;
  rep(i,n-1)for(int j=i+1;j<n;j++){
    if(b[i][j]<a[i][j]){
      cout<<-1<<endl;
      return 0;
    }
    ll tmp=0;
    ll add=b[i][j];
    rep(k,n){
      if(k!=i && k!=j){
        tmp=b[i][k]+b[k][j];
        if(tmp==b[i][j]){
          add=0;
          //b[i][j]=llMAX/100;
          //b[j][i]=llMAX/100;
          break;
        }
      }
    }
    ans+=add;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1664
// Problem Code: abc174_e

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int logs(int N, int K, vector<int>& A) {
	int low, mid, high;
	low = 1;
	high = *max_element(A.begin(), A.end());

	// helper function
	auto good = [&](int len) {
		int cuts = 0;
		for (int& log: A)
			cuts += (log + len - 1) / len - 1;
		return cuts <= K;
	};

	// binary search
	while (low < high) {
		mid = low + (high - low) / 2;
		if (good(mid))
			high = mid;
		else
			low = mid + 1;
	}

	return high;
}

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
		cin >> A[i];
	cout << logs(N, K, A);
	return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

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

    int a, b;
    cin >> a >> b;

    // the largest multiplier of k
    // leas or equal than b
    int largest = (b / k) * k;

    if (largest >= a) {
        cout << "OK" << endl;
    }
    else {
        cout << "NG" << endl;
    }


    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<cstring>
#define ll long long
using namespace std;
const int INF = 1<<30;
const int maxn = 2e5+5;
int a[maxn];
int ans = INF;
int main()
{
    int k,n;
    cin>>k>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<n;i++)
    {
        ans = min(ans,k-(a[i+1]-a[i]));
    }
    ans = min(ans,a[n]-a[1]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            a -= 1;
            b -= 1;
            int result = 0;

            while (b > 0)
            {
                b -= a;
                ++result;
            }


            Console.WriteLine($"{result}");
        }
    }
}


Measured memory_bytes: 13268
#include "bits/stdc++.h"
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> l(n);
	for (int i = 0; i < n; i++) {
		int l_in;
		cin >> l_in;
		l.at(i) = l_in;
	}

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

	int ans = 0;
	for (int i = 0; i < n - 2; i++) {
		int a = l.at(i);
		for (int j = i + 1; j < n - 1; j++) {
			int b = l.at(j);
			for (int k = j + 1; k < n; k++) {
				int c = l.at(k);
				if (c < a + b) {
					ans++;
				} else {
					break;
				}
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
# 入力
A,B,C,D=map(int,input().split())

if B<=C:
  print(0)
elif A<=C and C<=B and B<=D:
  print(B-C)
elif C<=A and B<=D:
  print(B-A)
elif C<=A and A<=D and D<=B:
  print(D-A)
elif D<=A:
  print(0)
elif C<=A and A<=D and D<=B:
  print(D-A)
elif A<=C and D<=B:
  print(D-C)
elif A<=C and C<=B and C<=D:
  print(C-A)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
    Main(){
	Scanner sc= new Scanner(System.in);

	while(sc.hasNext()){
	    String str = sc.next();
	    char[] ch = str.toCharArray();

	    for(int i = str.length()-1; i >= 0; i--)
		System.out.print(Character.toString(ch[i]));
	    System.out.println();
	}
    }

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

Measured memory_bytes: 11000
def main():
    # 差分だけ微調整する解法
    N, K = map(int, input().split(" "))
    p = list(map(int, input().split(" ")))
    answer = sum(p[:K])
    tmp = sum(p[:K])
    for i in range(N - K):
        tmp = tmp + p[i+K] - p[i]
        answer = max(answer, tmp)
    print((answer + K) / 2)


if __name__ == '__main__':
    main()

Measured memory_bytes: 25060
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CsharpSpiral {
    partial class Program {
        static void Main(string[] args) {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }
        public void Solve(ConsoleInput cin) {
            var A = cin.ReadInt;
            var B = cin.ReadInt;
            var R = Enumerable.Range(1, 1300).Where(i => i * 8 / 100 == A).Where(i => i * 10 / 100 == B);
            var ans = R.Any() ? R.Min() : -1;
            Console.WriteLine(ans);
        }


    }

    static class ExtendClass {
        public static void Swap<T>(this T[] X, int i, int j) {
            T tmp = X[i];
            X[i] = X[j];
            X[j] = tmp;
        }
        public static string Join<T>(this T[] X, string separator = " ") => string.Join(separator, X);
        public static S[] Clone<S>(this S[] src) where S : struct {
            var res = new S[src.Length];
            Array.Copy(src, res, src.Length);
            return res;
        }
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private readonly char _separator = ' ';
        private readonly Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for(long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint fact(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		for(;k<=n;k++) memo[k]=memo[k-1]*k;
	}
	return memo[n];
}

mint fact_inverse(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		memo[n]=inverse(fact(n));
		for(int i=n;i>k;i--) memo[i-1]=memo[i]*i;
	}
	return memo[n];
}

mint choose(int n,int k,int type=0){
	if(k<0 || n<k) return 0;
	if(type==0){
		return fact(n)*fact_inverse(k)*fact_inverse(n-k);
	}
	else{
		if(k>n-k) k=n-k;
		mint res=fact_inverse(k);
		rep(i,k) res*=n-i;
		return res;
	}
}

int main(){
	int h,w,n; scanf("%d%d%d",&h,&w,&n);
	vector<pair<int,int>> P(n+1);
	rep(i,n) scanf("%d%d",&P[i].first,&P[i].second), P[i].first--, P[i].second--;
	P[n]={h-1,w-1};

	sort(P.begin(),P.end(),[](const pair<int,int>& a,const pair<int,int>& b){
		return a.first+a.second<b.first+b.second;
	});

	choose(h+w,h);

	vector<mint> dp(n+1);
	rep(i,n+1){
		int y,x; tie(y,x)=P[i];
		dp[i]=choose(y+x,y);
		rep(j,i){
			int r,c; tie(r,c)=P[j];
			if(r<=y && c<=x) dp[i]-=dp[j]*choose(y-r+x-c,x-c);
		}
	}
	printf("%d\n",dp[n].to_int());

	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int dp[50];

int fib(int);

int main(void){
  int i,n,b;
  for(i=0;i<50;i++)dp[i]=-1;
  scanf("%d",&n);
  b=fib(n);
  printf("%d\n",b);
  return 0;
}

int fib(int n){
  if(n==0||n==1){
    return dp[n]=1;
  }
  if(dp[n]!=-1){
    return dp[n];
  }
  return dp[n]=fib(n-1)+fib(n-2);
}



Measured memory_bytes: 2044
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define gap                        ' '
#define EPS                        1e-9
#define P_INF                      2e9+17
#define N_INF                     -2e9-17
#define MOD                        1000000007
#define PI                         2*acos(0.0)
#define All(x)                     x.begin(),x.end()
#define Mem(Name, type)            memset(Name, type, sizeof(Name))

template<typename T>
T GCD(T a, T b) { return a ? GCD(b % a, a) : b; }

template<typename T>
T LCM(T a, T b) { return (a * b) / GCD(a, b); }

template<typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto ob : v) os << ob << " ";
    return os;
}

template<typename T, typename S>
std::ostream &operator<<(std::ostream &os, const std::map<T, S> &v) {
    for (auto ob : v) os << ob.first << " : " << ob.second << std::endl;
    return os;
}

using ld = double;
using ll = long long int;
using ul = unsigned long long int;
using namespace std;

class BFrog2 {
    int n, k;
    vector<int> h;
    vector<int> dp;

    int MiniCost(int pos) {
        if (pos == n - 1) return 0;
        if (pos > n - 1) return P_INF;
        if (dp[pos] < P_INF) return dp[pos];

        for (int i = 1; i < k + 1; ++i) {
            int partialAns = P_INF;
            if (pos + i <= n - 1) {
                partialAns = abs(h[pos] - h[pos + i]) + MiniCost(pos + i);
            }
            dp[pos] = min(dp[pos], partialAns);
        }

        return dp[pos];
    }

public:
    void solve(std::istream &in, std::ostream &out) {
        in >> n >> k;
        h.resize(n);
        dp.resize(n);
        for (int i = 0; i < n; ++i) {
            in >> h[i];
            dp[i] = P_INF;
        }
        out << MiniCost(0) << endl;
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    BFrog2 solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 11920
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int h, w, n;
  cin >> h >> w >> n;
  cout << n / max(h, w) + (n % max(h, w) != 0);
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int s=S.size();
  for(int i=0;i<s;i++){
    char x=S[i]+N;
    if(x>'Z')x-=26;
    cout << x;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,a,b;
  scanf("%d",&n);
  if(n==1){
    printf("Hello World\n");
  }
  else if(n==2){
    scanf("%d",&a);
    scanf("%d",&b);
    printf("%d\n",a+b);
  }
  return 0;
}


Measured memory_bytes: 1692
s=input()
m=10**9+1
for alpha in set(s):
    temp=alpha+s+alpha
    M=0
    now=0
    for i,key in enumerate(temp):
        if key==alpha:
            if M<i-now-1: M=i-now-1
            now=i
    if m>M: m=M

print(m)

Measured memory_bytes: 9120
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

int main() {
	
	string s,t;
	cin>>s>>t;
	int k = 0;
	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] != t[i])
		{
			k++;
		}
	}
	cout<<k;
	return 0;
}

Measured memory_bytes: 3820
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let n: usize = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.parse().unwrap()
    };

    let mut a = vec![vec![0; 10]; 10];
    for i in 1..(n + 1) {
        let len = i.to_string().len();
        let msd = i / 10usize.pow(len as u32 - 1);
        let lsd = i % 10;

        a[msd][lsd] += 1;
    }

    let mut ans = 0;
    for i in 1..10 {
        for j in 1..10 {
            ans += a[i][j] * a[j][i];
        }
    }
    println!("{}", ans);
}

fn calc(a: usize, b: usize, n: usize) -> usize {
    let mut count = 0;
    for i in 1..(n + 1) {
        let len = i.to_string().len();
        let msd = i / 10usize.pow(len as u32 - 1);
        let lsd = i % 10;

        if msd == a && lsd == b {
            count += 1;
        }
    }

    count
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main() {
    int a, b, max;
    
    cin >> a >> b;
    
    max = a+b;
    if(max < a-b) max = a-b;
    if(max < a*b) max = a*b;
    
    cout << max << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		for(int i=1;i<=1000;i++) {
			double x = i*0.08;
			double y = i*0.1;
			int eight = (int)x;
			int ten = (int)y;
			if(eight==a && ten==b) {
				System.out.println(i);
				System.exit(0);
			}
		}
			
		System.out.println(-1);
		
	}	
}


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

int main() {
  int K, X = 0;
  cin >> K >> X;

  int minN = 0;

  minN = X - (K-1);

  for (int i = 0; i < 2 * K -1; i++) {
	cout << (minN + i) << " ";
  }
 
  cout << endl;

  return 0;
}


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


using namespace std;

int main(){
    int N; cin >> N;
    vector<int> d(N);
    for(int i=0; i<N; i++){
        cin >> d.at(i);
    }
    int sum = 0;
    for(int i=0; i<N-1; i++){
        for(int j=i+1; j<N; j++){
            sum += d.at(i) * d.at(j);
        }
    }
    cout << sum << endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n+1];
  for(int i=1;i<=n;++i)
    cin>>a[i];
  int tot=0;
  for(int i=1;i<=n;i+=2)
    if(a[i]%2==1)
      ++tot;
  cout<<tot<<endl;
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
int d[200010],dp[1010][1010];
double w[1000],v[1000];
double box[200010];

int main(){
  while(1){
    cin >> n;
    if(!n)break;
    rep(i,0,n)cin >> d[i];
    sort(d,d+n);
    l = 0;
    rep(i,1,n-1)l += d[i];
    print(l / (n-2));
  }
  return 0;
}


Measured memory_bytes: 3020
#include <stdio.h>
 
int main(void)
 
{
 
int a,b,c,i,s;
 
s=0;
 
scanf("%d %d %d",&a,&b,&c);
 
for(i=a;i<=b;i++)
 
{
 
if(c%i==0)
 
{
 
s=s+1;
 
}
 
}
 
printf("%d\n",s);
 
return 0;
 
}
 

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

int main() {
  int n;
  cin >> n;
  int odd = n-n/2;
  double ans = (double)odd/n;
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 256
N,M= [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
l = [[] for i in range(N+1)]
for i in range(M):
    a,b= [int(x) for x in input().split()]
    l[a].append(b)
    l[b].append(a)
ans = 0
for i in range(1,N+1):
    hantei = True
    for j in l[i]:
        if h[i-1] <= h[j-1]:
            hantei = False
            break
    if hantei:
        ans += 1
print(ans)

Measured memory_bytes: 29516
def main():
    n,m=map(int,input().split())
    L=[list(map(int,input().split())) for _ in range(m)]
    if m>1:
        for i in range(m-1):
            for j in range(i+1,m):
                if L[i][0]==L[j][0] and L[i][1]!=L[j][1] :
                    print(-1)
                    return
    if n>1:
        for l in L:
            if l[0]==1 and l[1]==0:
                print(-1)
                return
    if n==1:
        ans=['0']
    else:
        ans=list('1'+'0'*(n-1))
    for l in L:
        ans[l[0]-1]=str(l[1])
    print(''.join(ans))
main()

Measured memory_bytes: 3064