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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

typedef pair<ll, pair<ll, ll>> kouho;

int main() {

    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];


    int ans = 0;
    int nowCount = 0;
    rep(i, 105) {
        int divide = 0;
        bool stopFlag = true;
        rep(j, n) {
            if(h[j] <= nowCount && !stopFlag) {
                stopFlag = true;
                continue;
            }
            if(h[j] > nowCount && stopFlag) {
                stopFlag = false;
                divide++;
                continue;
            }
        }

        if(divide == 0) break;
        ans += divide;
        nowCount++;
    }

    cout << ans << endl;

    return 0;
}



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

using namespace std;

int main() {
	int n;
	
	cin >> n;
	vector<long long> a(n+3);

	int count = 0;
	int t = 0;

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

	int i = 0;
	while(1){
		if (a[i] < a[i+1]) {
			while (a[i] <= a[i + 1]) {
				i++;
				if (i >= n - 1)break;
			}
			count++;
			i++;
			if (i == n - 1) {
				count++;
				break;
			}

		}
		else if (a[i] > a[i + 1]) {
			while (a[i] >= a[i + 1]) {
				i++;
				if (i >= n - 1)break;
			}
			count++;
			i++;
			if (i == n - 1) {
				count++;
				break;
			}
		}
		else {
			i++;
			if (i >=n-1)break;
		}

	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const long long INF = LLONG_MAX / 2;

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

    while(--t >= 0){
        long long n;
        int a, b, c, d;
        cin >> n >> a >> b >> c >> d;

        const int mag[] = {2, 3, 5};
        const int cost[] = {a, b, c};

        map<long long, long long> dp;
        priority_queue<
            pair<long long, long long>,
            vector<pair<long long, long long> >,
            greater<pair<long long, long long> > > pq;
        dp[n] = 0;
        pq.push(make_pair(0, n));

        long long ans = INF;
        if(d < INF / n)
            ans = n * d;

        while(!pq.empty()){
            auto [tmp, x] = pq.top();
            pq.pop();
            if(dp[x] < tmp || ans < tmp)
                continue;

            if(x < INF / d)
                ans = min(ans, d * x + tmp);

            for(int i=0; i<3; ++i){
                long long tmp1 = tmp + cost[i] + (x % mag[i]) * d;
                long long x1 = x / mag[i];
                if(dp.find(x1) == dp.end() || tmp1 < dp[x1]){
                    dp[x1] = tmp1;
                    pq.push(make_pair(tmp1, x1));
                }

                if(x % mag[i] != 0){
                    long long tmp2 = tmp + cost[i] + (mag[i] - x % mag[i]) * d;
                    long long x2 = x / mag[i] + 1;
                    if(dp.find(x2) == dp.end() || tmp2 < dp[x2]){
                        dp[x2] = tmp2;
                        pq.push(make_pair(tmp2, x2));
                    }
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}


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


int main()
{
    /*
    string s;
    cin>>s;
    if(s=="ABC")
    {
        cout<<"ARC"<<endl;
    }
    else
    {
        cout<<"ABC"<<endl;
    }
    */
    int n,k;
    cin>>n>>k;
    map <int,int> mp;
    for(int i=1;i<=k;i++)
    {
        int d;
        cin>>d;
        for(int j=1;j<=d;j++)
        {
            int a;
            cin>>a;
            mp[a]++;
        }
    }
    int count=0;
    for(int i=1;i<=n;i++)
    {
        if(mp[i]==0)
        {
            count++;
        }
    }

    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
    ll a,b,c,n;
    cin>>a>>b>>c>>n;
    ll ans=0;
    for(ll i=0;i<3010;i++)for(ll j=0;j<3010;j++){
	ll rem=n-i*a-j*b;
	if(rem%c==0){
	    rem/=c;
	    if(rem>=0)ans++;
	}
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
signed main()
{
    int l,r,d,ans=0;
    cin>>l>>r>>d;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
        ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
using P = pair<int, int>;

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

  if(a == b) cout << c << endl;
  if(a == c) cout << b << endl;
  if(b == c) cout << a << endl;
  return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
    cin>>a>>b>>c;
    cout<<a<<" "<<b<<" "<<-a-b+3*c<<endl;
    cout<<-2*a-b+4*c<<" "<<c<<" "<<2*a+b-2*c<<endl;
    cout<<a+b-c<<" "<<-b+2*c<<" "<<-a+2*c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/format.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/optional.hpp>

#ifdef DEBUG
#include "libs/debug.cpp"
#define DEBUG 1
#else
#define DEBUG 0
#endif

#define rep(i, n) repr((i), 0, (n))
#define repr(i, a, t) reps((i), (a), (t), 1)
#define reps(i, a, t, s) for (long long (i) = (a); (i) < (long long)(t); (i) += (s))
#define rrep(i, n) rrepr((i), (n) - 1, 0)
#define rrepr(i, a, t) rreps((i), (a), (t), 1)
#define rreps(i, a, t, s) for (long long (i) = (a); (i) >= (long long)(t); (i) -= (s))
#define each(v, c) for (auto &&(v) : (c))
#define all(c) (c).begin(), (c).end()

using namespace std;
namespace mp = boost::multiprecision;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using ml = mp::cpp_int;
template<typename T>
using optional = boost::optional<T>;
const auto none = boost::none;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

int main() {
  cout << fixed << setprecision(10);
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ifstream ifs;
  if (DEBUG) {
    ifs.open("src/_in.txt");
    cin.rdbuf(ifs.rdbuf());
  }

  ll N, A, B;
  cin >> N >> A >> B;
  ll ma = B * (N - 1) + A;
  ll mi = A * (N - 1) + B;
  cout << max(0ll, ma - mi + 1) << endl;
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)

char s[5009];
ull h[5009];
ull p[5009];
ull base=3009;
int n;
int mp[300];
ull seg(int x,int y)
{
    return h[y]-h[x-1]*p[y-x+1];
}

int f(int x)
{
    for(int i=1; i<=n-x; i++)
    {
        ull p=seg(i,i+x);
        for(int j=i+x+1; j<=n-x; j++)
        {
            if(p==seg(j,j+x))
                return 1;
        }
    }
    return 0;
}
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1; i<=n; i++)
        h[i]=h[i-1]*base+s[i];
    p[0]=1;
    for(int i=1; i<=5000; i++)
        p[i]=p[i-1]*base;
    int l=1,h=n,ans=0;
    while(l<=h)
    {
        int mid=(l+h)/2;
//        cout<<mid<<endl;
        if(f(mid))
        {
            ans=mid;
            l=mid+1;
        }
        else
            h=mid-1;
    }
    int fg=0;
    for(int i=1; i<=n; i++)
    {
        mp[s[i]]++;
        if(mp[s[i]]>1)
            fg=1;
    }
    cout<<ans+fg;



}


Measured memory_bytes: 384
using System;

namespace procon
{
    class Program
    {
        static void Main(string[] args)
        {
            solve0216();
        }
        static void solve0000()
        {
            int i, j;
            for (i = 1; i <= 9; i++)
            {
                for (j = 1; j <= 9; j++)
                {
                    Console.WriteLine("{0}x{1}={2}", i, j, i * j);
                }
            }
        }
        static void solve0216()
        {
            int amount;
            while( (amount = int.Parse(Console.ReadLine())) >= 0)
            {
                int value = 1150;
                amount -= 10;
                if (amount > 0)
                {
                    value += 125 * Math.Min(amount, 10);
                    amount -= 10;
                }
                if (amount > 0)
                {
                    value += 140 * Math.Min(amount, 10);
                    amount -= 10;
                }
                if (amount > 0)
                {
                    value += 160 * amount;
                }
                Console.WriteLine(4280 - value);
            }
        }
    }
}



Measured memory_bytes: 15872
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cctype>
#include <sstream>
#include <algorithm>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;

bool ck(string s){
  map<char,int>m;
  m['A']=0;m['I']=0;m['D']=0;m['U']=0;m['N']=0;m['Y']=0;
  for(int i=0; i<s.size(); i++) m[s[i]]++;
  if(m['A']==2 && m['I']==1 && m['D']==1 && m['U']==1 &&  m['N']==2 && m['Y']==1) return true;
  return false;
}

int main() {
  string s;
  cin >> s;
  if(s.size()<8) pr(s);
  else {
    for(int i=0; i+7<s.size(); i++) {
      if(ck(s.substr(i,8))) {
	s=s.substr(0,i)+"AIZUNYAN"+s.substr(i+8);
	i+=7;
      }
    }
    pr(s);
  }
  return 0;
}


Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int N;
vector<int> a(101, 0);

int main(void){
	
	scanf("%d", &N);
	for(int i = 0; i < N; ++i) scanf("%d", &a[i]);
	
	int mx = *max_element(a.begin(), a.begin() + N);
	int mn = *min_element(a.begin(), a.begin() + N);
	
	printf("%d\n", mx - mn);
	
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100005
#define NIL -1

struct Node {
    int parent, left, right;
};

struct Node Tree[MAX];
int n;

void preParse(int u) {
	if ( u == NIL ) return;
	printf(" %d",u);
	preParse(Tree[u].left);
	preParse(Tree[u].right);
}
void inParse(int u) {
	if ( u == NIL ) return;
	inParse(Tree[u].left);
	printf(" %d",u);
	inParse(Tree[u].right);
}

void postParse(int u) {
	if ( u == NIL ) return;
	postParse(Tree[u].left);
	postParse(Tree[u].right);
	printf(" %d",u);
}

int main () {
	int i, v, l, r, root;

	scanf("%d",&n);
	for ( i = 0; i < n; i++ ) {
		Tree[i].parent = NIL;
	}

	for ( i = 0; i < n; i++ ) {
		scanf("%d%d%d", &v, &l, &r);
		Tree[v].left = l;
		Tree[v].right = r;
		if (l != NIL) Tree[l].parent = v;
		if (r != NIL) Tree[r].parent = v;
	}

	for ( i = 0; i < n; i++ ) {
		if (Tree[i].parent == NIL) root = i;
	}

	printf("Preorder\n");
	preParse(root);
	printf("\nInorder\n");
	inParse(root);
	printf("\nPostorder\n");
	postParse(root);
	printf("\n");

    return 0;
}


Measured memory_bytes: 1992
#include <iostream>
using namespace std;
int main(void){
    long long n,a,b,c,x,A;
    
    cin>>n>>a;
    
    A=a;
    
    c=a;
    
    for(x=1; x<n; x++){
        
        cin>>b; 
        
        c+=b;
        
        if(a<b){
            a=b;
        }
        if(A>b){
            A=b;
        }
        
    }
    cout<<A<<" "<<a<<" "<<c<<endl;
    
    return 0;
}



Measured memory_bytes: 3116
from collections import defaultdict as d

n = int(input())
arr = list(map(int, input().split()))

som = []
diff = []

dsom = d(int)
ddiff = d(int)
for i in range(n):
	som.append(i+1+arr[i])
	diff.append((i+1-arr[i]))
	
	dsom[som[-1]] += 1
	ddiff[diff[-1]] += 1

val = 0
for k, v in dsom.items():
	val += (v * ddiff[k])
	
print(val)


Measured memory_bytes: 76184
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

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

    while(1) {
        int n, m, p;
        cin >> n >> m >> p;
        m--;
        if (n == 0) break;
        // DDD(n, m, p);
        vector<int> x(n);
        int sm = 0;
        REP(i, n) {cin >> x[i]; sm += x[i]; }
        int total = sm * (100 - p);
        // D(total);
        cout << (x[m] == 0 ? 0 : total / x[m]) << endl;
    }
}



Measured memory_bytes: 3124
n = int(input())
s = [input() for _ in range(n)]
ac=0
wa=0
tle=0
re=0

for i in range(0,n):
    if s[i] == "AC":
        ac +=1
    elif s[i] == "WA":
        wa += 1
    elif s[i] == "TLE":
        tle += 1
    else:
        re += 1
        
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

Measured memory_bytes: 16256
fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let mut ans = 0;
    for i in 1..=n {
        let m = n / i;
        ans += (1 + m) * m / 2 * i;
    }
    println!("{}", ans);
}

Measured memory_bytes: 2164
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 1e5 + 5;
ll n, s0, sf, a[N], b[N];
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 0; i < n + 1; i++)
        cin >> a[i], s0 += a[i];
    for(int i = 0; i < n; i++)
        cin >> b[i];
    for(int i = 0; i < n; i++){
        int mn = min(a[i], b[i]);
        b[i] -= mn;
        a[i] -= mn;
        if(b[i] > 0) a[i + 1] -= min(a[i + 1], b[i]);
    }
    for(int i = 0; i < n + 1; i++)
        sf += a[i];
    cout << s0 - sf;
    return 0;
}


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

int main() {
    int n, a;
    cin >> n >> a;
    int nn = n%1000;
    int m3 = (nn/100)%5;

    if(n>a){
        if(m3*100+(nn%100) > a){
            cout << "No" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int n, m;
	cin >> n >> m;
	vector<int> h(n+1);
	REP1(i, n) cin >> h[i];
	//n頂点m枝に対して隣接リストをつくる。
	int u, v;
	//vector< vector <int> > ls(n); //0-origin
	vector< vector <int> > ls(n+1); //1-origin
	REP(i, m){ 
		cin >> u >> v; 
		ls[u].push_back(v); 
		ls[v].push_back(u);
	}
	//
	REP1(i, n){
		int now = h[i];
		bool ch = true;
		REP(j, ls[i].size()) if(h[ls[i][j]] >= now) ch = false;
		if(ch) ans ++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 8752
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)

var N int
var P []int

func main() {
	sc.Split(bufio.ScanWords)
	N = nextInt()
	P = make([]int, N)

	ans := 1
	minP := 0
	for i := 0; i < N; i++ {
		P[i] = nextInt()
		if i == 0 {
			minP = P[0]
			continue
		}
		minP = minInt(P[i], minP)
		if P[i] <= minP {
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 3584
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int K = Integer.parseInt(S[1]);
    List<Integer> list = new ArrayList<>();
    for(int i = 0; i < N; i++){
      list.add(Integer.parseInt(sc.nextLine()));
    }
    Collections.sort(list);
    int ans = 1000000000;
    for(int i = 0; i < N-K+1; i++){
      if(list.get(i+K-1)-list.get(i) < ans){
        ans = list.get(i+K-1)-list.get(i);
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 93416
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){
  char c;
  cin >> c;
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
    cout << "vowel" << endl;
    return 0;  
  }
  
  cout << "consonant" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
//fflush(stdin);
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n,k;
    cin>>n>>k;
    ve <ll> arr(n);
    rep (i,0,n)
    {
        cin>>arr[i];
    }
    if (k>=n)
    {
        k=n-1;
    }
    ve <ll> dp(n,1000000000000000);
    dp[n-2]=abs (arr[n-1]-arr[n-2]);
    dp[n-1]=0;
    rev (i,n-2,n-1-k)
    {
        dp[i]=abs(arr[i]-arr[n-1]);
        rep (j,i+1,n-1)
        {
            dp[i]=min(dp[j]+abs(arr[j]-arr[i]),dp[i]);
        }
    }
    rev (i,n-k-1,0)
    {
        rep (j,i+1,i+k+1)
        {
            dp[i]=min(dp[j]+abs(arr[j]-arr[i]),dp[i]);
        }
    }
    cout<<dp[0]<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, Q;
	int S[100010], Sdiv[100010], ans[100010];
	int A[100010], X[100010];
	cin >> N >> Q;

	eFOR(i,1, N) {
		cin >> A[i];
		S[i] = S[i - 1] + A[i];
		Sdiv[i] = A[i];
		if (i - 2 > 0) {
			Sdiv[i] += Sdiv[i - 2];
		}
	}
	REP(i, Q) {
		cin >> X[i];
	}

	REP(q, Q) {
		int ng = 0;
		int ok = N;
		while (ok - ng > 1) {
			int mid = (ng + ok) / 2;
			if (A[mid] < X[q]) {
				ng = mid;
			}else {
				int upper = N - mid + 1;
				int lower = mid - (lower_bound(A, A + N + 1, max(1LL, 2 * X[q] - A[mid])) - A) + 1;
				(upper > lower ? ng : ok) = mid;
			}
		}

		int res = S[N] - S[ok - 1];
		int tf = N - (N - ok + 1) * 2;
		if (tf > 0)res += Sdiv[tf];
		ans[q] = res;

	}



	REP(i, Q) {
		cout << ans[i] << endl;
	}


	return 0;
}



Measured memory_bytes: 5632
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define PI (acos(-1))
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/



ll N,M;
vector<ll> a;

void input() {
	scanf("%lld", &M);
	N=M/2;
	a.assign(M,0);
	rep(i, M) cin>>a[i];
	sort(all(a));
}

void solve() {
	ll ans = a[N]-a[N-1];


	printf("%lld\n", ans);
}

signed main() {
	input();
	solve();
	return 0;
}


Measured memory_bytes: 1024
s = input()
n = len(s)
ans = 0
i = 1

def dfs(i, s, ans):
    if i==n:
        #print(i, 'bottom', s, ans)
        ans += sum([int(i) for i in s.split('+')])
        return False, ans
    else:
        #print(i, 'left',s, ans)
        tf, ans = dfs(i+1, s, ans)
        if tf:
            return True, ans
        else:
            #print(i, 'right',s, ans)
            p = i + s.count('+')
            s = s[:p]+'+'+s[p:]
            tf, ans = dfs(i+1,  s, ans)
            return tf, ans

_, a = dfs(i, s, ans)
print(a)


Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cassert>
#include<cstring>
#include<algorithm>
using namespace std;

const int N = 100;
short dp[N+3][N+3][N+3][N+3];
int s[N+3][N+3];
char a[N+3][N+3];
int n,m,sx,sy;

int getsum(int lx,int rx,int ly,int ry) {return s[rx][ry]-s[lx-1][ry]-s[rx][ly-1]+s[lx-1][ly-1];}

int updmax(short &x,short y) {x = x>y?x:y;}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++) scanf("%s",a[i]+1);
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
		{
			s[i][j] = (a[i][j]=='o'?1:0)+s[i-1][j]+s[i][j-1]-s[i-1][j-1];
			if(a[i][j]=='E') {sx = i,sy = j;}
		}
	}
	memset(dp,213,sizeof(dp));
	dp[0][0][0][0] = 0; short ans = 0;
	for(int l=0; sy-l>0; l++)
	{
		for(int r=0; sy+r<=m; r++)
		{
			for(int u=0; sx-u>0; u++)
			{
				for(int d=0; sx+d<=n; d++)
				{
					updmax(ans,dp[l][r][u][d]);
					int ly = max(1+r,sy-l),ry = min(m-l,sy+r),lx = max(1+d,sx-u),rx = min(n-u,sx+d);
//					printf("l%d r%d u%d d%d x[%d,%d] y[%d,%d]\n",l,r,u,d,lx,rx,ly,ry);
					if(sx+d<n-u)
					{
						updmax(dp[l][r][u][d+1],dp[l][r][u][d]+getsum(sx+d+1,sx+d+1,ly,ry));
					}
					if(sx-u>1+d)
					{
						updmax(dp[l][r][u+1][d],dp[l][r][u][d]+getsum(sx-u-1,sx-u-1,ly,ry));
					}
					if(sy+r<m-l)
					{
						updmax(dp[l][r+1][u][d],dp[l][r][u][d]+getsum(lx,rx,sy+r+1,sy+r+1));
					}
					if(sy-l>1+r)
					{
						updmax(dp[l+1][r][u][d],dp[l][r][u][d]+getsum(lx,rx,sy-l-1,sy-l-1));
					}
				}
			}
		}
	}
	printf("%d\n",(int)ans);
	return 0;
}

Measured memory_bytes: 220160
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int mod = 1_000_000_007;
        Combination com = new Combination(n, mod);
        long ans = 0L;
        int m = k < n ? k : n-1;
        for (int i = 0; i <= m; i++) {
            long z = com.comb(n, i);
            long c = com.comb(n-1, i);
            ans = (ans + (z * c % mod))%mod;
        }
        System.out.println(ans);
        sc.close();

    }

}

class Combination {

    /** factorial:階乗 */
    private long fac[];
    /** inverse:逆元（ここでは、fac[i]をMOD-2乗したものをMODで割った余り） */
    private long inv[];
    /** 除数 */
    private int mod;

    /**
     * コンストラクタ
     * @param size 組み合わせの対象となる個数
     * @param mod 除数
     */
    public Combination(int size, int mod){
        this.fac = new long[size +1];
        this.inv = new long[size +1];
        this.mod = mod;

        this.fac[0] = 1;
        this.inv[0] = 1;

        for(int i = 1; i <= size; i++){
            fac[i] = (fac[i -1] * i) %mod;
            inv[i] = modPow(fac[i], (int)mod -2) %mod;
        }
    }

    /**
     * n個の中からr個選ぶ組み合わせの数（nCr）をmodで割った余りを算出する
     * @param n 元の集合の要素数
     * @param r 組み合わせる要素数
     * @return nCr % mod
     */
    public long comb(int n, int r){
        return fac[n] * inv[r] %mod * inv[n - r] %mod;
    }

    /**
     * base^exp をmodで割った余りを算出する
     * @param base 基数
     * @param exp 指数
     * @return base^exp % mod
     */
    private long modPow(long base, int exp) {
        long ret = 1;
        while(exp > 0){
            if((exp & 1) == 1){
                ret = ret * base %mod;
            }
            base = base * base %mod;
            exp >>= 1;
        }
        return ret;
    }

}



Measured memory_bytes: 27476
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> cnt(k, 0);
  FOR(i, 1, n + 1) { ++cnt[i % k]; }
  ll ans = 0;
  REP(a, k) {
    ll b = (k - a) % k;
    ll c = (k - a) % k;
    if ((b + c) % k != 0) continue;
    ans += cnt[a] * cnt[b] * cnt[c];
  }
  cout << ans << endl;
  return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
    int n;
    cin >> n;
  	cout << "Christmas" ;
  	rep(i,25-n) cout << " Eve";
  	cout << endl;
  	return;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
  long long n;
  cin >> n;
  long long k = sqrt(n+1)-1;
  long long c=0;
  for(int i=1;i<=k;i++){
    if (n%i==0){
      c += n/i-1;
    }
  }
  cout << c << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int [][][]room = new int[4][3][10];
        int n = sc.nextInt();
        for(int i = 0; i < n; i++){
            int b = sc.nextInt();//棟
            int f = sc.nextInt();//階
            int r = sc.nextInt();//部屋
            int v = sc.nextInt();//番目
            room[b - 1][f - 1][r - 1] += v;
        }
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 3; j++){
                for(int k = 0; k < 10; k++){
                    System.out.print(" " + room[i][j][k]);
                }
                System.out.println();
            }
            if(i != 3)	System.out.println("####################");
        }
    }
}



Measured memory_bytes: 30096
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int weeks;
    int result = 100000;
    scanf("%d", &weeks);
    
    for(int i=0;i<weeks;i++) {
        result=result*105/100;
        if (result%1000!=0) {
            result=(result/1000+1)*1000;
        }
    }
    printf("%d\n", result);
    return 0;
}



Measured memory_bytes: 2064
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
ll countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}


int main() {
	string s;
	cin >> s;
	if (s[0] == s[1] && s[1] == s[2])cout << "Yes" << endl;
	else if (s[3] == s[1] && s[1] == s[2])cout << "Yes" << endl;
	else cout << "No" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 1000001;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const int mod =  1e9+7;

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

string s;
cin>>s;
if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3])
{
	cout<<"Bad";
	return 0;
}
cout<<"Good";
}

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

int main() {
	long long max=-2147483648;
	
	int N;
	cin >> N;
	
	int F[N][10];
	for(int i=0; i<N; i++){
	for(int j=0; j<10; j++){
		cin >> F[i][j];
	}
	}
	long long P[N][11];
	for(int i=0; i<N; i++){
	for(int j=0; j<11; j++){
		cin >> P[i][j];
	}
	}
	
	
	for(int i=1; i<1024; i++){
		int j=i;
		int doji[N]={0};
		for(int s=0; s<10; s++){
		for(int t=0; t<N; t++){
			if(j%2 ==1){doji[t]+= F[t][s];}
		}
		j/=2;
		}
		
		
		long long zante=0;
		for(int n=0; n<N; n++){
			zante += P[n][doji[n]];
		}
		if(zante>max){max=zante;}
	}
	


	cout << max <<endl;	
	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define uni(x) sort(all(x)),x.resize(unique(all(x))-x.begin());
#define GETPOS(c,x) (lower_bound(all(c),x)-c.begin())
#define lown1(x,val) low(in(x),val)-x
#define lowm1(x,val) low(im(x),val)-x
#define low1(x,nums,val) low(x+1,x+nums+1,val)-x
#define mst(x,val) memset((x),val,sizeof((x)))
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define far(i,V) for(auto &i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lcm(a,b) ((a)*(b))/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) ((x)&(-x))
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (((x)<0)?(x)%mo_num+mo_num:(x)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define Umap unordered_map<int,int>
#define P pair<int,int>
#define SET set<int>
#define mk make_tuple
#define eps 1e-6
//Remember cancel"#define endl '\n'" in interactive questions or use "<<flush"
#define endl '\n'
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
//#define yn(key) out(key?"Yes":"No")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define ik(i,k) i+1,i+1+k
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
#define db double
#define ll long long
#define got(container,num) get<num-1>(container)
#define int long long
#define print(a,n) fun(i)cout<<a[i]<<(i!=n?' ':endl);
#define outcase(x) cout<<"Case #"<<(++case_of_T)<<": "<<x<<endl;
#define ptcase(x) printf("Case #%d: %d\n",++case_of_T,x);
#define plcase(x) printf("Case #%lld: %lld\n",++case_of_T,x);
using namespace std;
//Remember to cancel the line below and declare INT=INT_MAX/2; when you want to change long to int
const int INF=LLONG_MAX/4,SINF=0x3f3f3f3f,Lim=1<<20,MINF=LLONG_MAX;
//const int INF=INT_MAX/4,SINF=0x3f;
// use C:printf("%.16f", x);  ->  printf("%.10f", x); can accelerate the program
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//down up left right
const int maxn=1e6+1e5;
int mo_num=1e9+7;
//const int mo_num=998244353;
int n,m,t,a[maxn],b[maxn],ans,case_of_T;
const int N=1e9;
void solve()
{
    cin>>n;
    int A=n/N,B=n%N;
//    out(A)
//    out(B)
    cout<<0<<" "<<0<<" ";
    if(!B)
    {
        cout<<N<<" "<<0<<" "<<0<<" "<<A;
    }else{
        A++;
        B-=N;
        cout<<A<<" "<<1<<" "<<-B<<" "<<N;
    }
    return ;
}
main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)solve();
    return 0;
}


Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        CF_Reader in = new CF_Reader();

        double a = in.Double();
        double b = in.Double();

        out.println(solve(a, b));

        out.close();
    }

    static int solve(double a, double b) {
        double n = Math.ceil(a / 0.08);
        double upperBound = Math.ceil((a + 1) / 0.08);
        for (double i = n; i < upperBound; i++) {
            if (Math.floor(i * 0.1) == b) return (int) i;
        }
        return -1;
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long Long() throws IOException {
            return Long.parseLong(next());
        }

        int Int() throws IOException {
            return Integer.parseInt(next());
        }

        double Double() throws IOException {
            return Double.parseDouble(next());
        }

        char Char() throws IOException {
            return next().charAt(0);
        }

        String Line() throws IOException {
            return br.readLine().trim();
        }
    }
}


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

long d;
long c[26];
long s[365][26];
long t[365];
long last[26];
long tmpAdd[26];

long nowAns;

long calcMinus(int day,long* last);
long calcScore();

int main(){
    nowAns = 0;
    cin >> d;
    for(int i=0;i<26;i++)cin >> c[i];
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            cin >> s[i][j];
        }
    }
    srand(1);

    for(int i=0;i<365;i++){
        t[i] = rand()%26 + 1;
    }
    nowAns = calcScore();

    for(int i=0;i<26;i++){
        last[i] = tmpAdd[i];
    }

    for(int cc=0;cc<200;cc++){
        
        int qq = 0;
        int qqbef = 0;
        int dd = 0;
        
        while(qq == qqbef){
            dd = rand()%365;
            qq = t[dd];
            qqbef = t[dd];
            for(int i=0;i<26;i++){
                if(s[dd][qq-1] < s[dd][i]){
                    qq = i+1;
                }
            }
        }
        
        t[dd] = qq;
        long tmp = calcScore();
        bool chk = true;
        if(tmp > nowAns){
            if(rand()%100 > 90){
                chk = false;
            }
        }else{
            if(rand()%100 > 10){
                chk = false;
            }
        }

        if(chk){
            for(int i=0;i<26;i++){
                last[i] = tmpAdd[i];
            }
        }else{
            t[dd] = qqbef;
        }
    }

    for(int i=0;i<d;i++){
        cout << t[i]<<endl;
    }
    
}


long calcMinus(int day,long* tmplast){

    long ans = 0;
    for(int i=0;i<26;i++){
        ans -= c[i] * (day - tmplast[i]);
    }

    return ans;
}

long calcScore(){
    long ans = 0;

    long tmplast[26];
    for(int i=0;i<26;i++){
        tmplast[i] = -1;
    }

    for(int i=0;i<d;i++){
        tmplast[t[i]-1] = i;
        ans += s[i][t[i]-1];
        ans += calcMinus(i,tmplast);
    }

    for(int i=0;i<26;i++){
        tmpAdd[i] = tmplast[i];
    }

    return ans;
    
}

Measured memory_bytes: 3708
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package here;

/**
 *
 * @author sokumar
 */
import java.util.*;
import java.io.*;
public class Main {
   
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter w = new PrintWriter(System.out);
        
            int n = sc.nextInt();
            int m = sc.nextInt();
            char [][]c = new char[n][m];
           for(int i=0;i<n;i++)
           {
               String s = sc.next();
               c[i] = s.toCharArray();
           }
           int f = 0;
           int [][]dp = new int[n][m];
           for(int j=1;j<m;j++)
           {
               if(c[0][j]=='.' && f==0)
                   dp[0][j] = 1;
               else
               {
                   dp[0][j] = 0;
                   f =1;
               }
           }
           f = 0;
           int mod = 1000000007;
           for(int i=1;i<n;i++)
           {
               if(c[i][0]=='.' && f==0)
                   dp[i][0] = 1;
               else
               {
                   dp[i][0] = 0;
                   f =1;
               }
           }
           for(int i=1;i<n;i++)
           {
               for(int j=1;j<m;j++)
               {
                   if(c[i][j]=='.')
                   {
                       dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod;
                   }
                   else
                       dp[i][j] = 0;
               }
           }
           w.println(dp[n-1][m-1]);
            
            
        w.close();
    }
    
    
}


Measured memory_bytes: 37712
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    set<int> st;
    int k,x; cin>>k>>x;
    for (int i = x-k+1; i < x+k; ++i) st.insert(i);
    for (auto &&e: st) cout << e << " ";
    cout << endl;
    return 0;
}


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

int main() {

    int a, b,c;
    scanf("%d%d%d", &a, &b,&c);

    int mindata = (a+b <= a+c ? a+b : a+c);
    mindata = (mindata < b+c ? mindata : b+c);
    
    printf("%d",mindata);
    return 0;

}


Measured memory_bytes: 128
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var K = parseInt(input[0].split(" ")[1]);
  var a = input[1].split(" ").map(i => parseInt(i));
  var dp = new Array(N+1);
  var mod=Math.pow(10,9)+7;
  for(var i=0;i<N+1;i++){
    var tmp=new Array(K+1).fill(0);
    dp[i]=tmp;
  }
  dp[0][0]=1;
  for(var i=0;i<N;i++){
    var sum=0;
    for(var j=0;j<K+1;j++){
      sum+=dp[i][j];
      sum%=mod;
      if(j>a[i]){
        sum+=mod-dp[i][j-a[i]-1];
        sum%=mod;
      }
      dp[i+1][j]=sum;
    }
  }
  var ans=dp[N][K];
  console.log('%s', ans);
  return ans;
}
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 113840
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int P[100001] = {};
    P[0] = 1;
    P[1] = 1;
    for (int i = 2; i <= 100000; i++) {
        if (P[i] == 0) {
            int j = 2;
            while(i*j <= 100000) {
                P[i*j] = 1;
                j++;
            }
        }
    }
    int likeP[50002] = {};
    likeP[0] = 0;

    for (int i = 1; i <= 50000; i++) {
        if (P[i*2-1] == 0 && P[i] == 0) likeP[i] = 1; 
    }
    int likesum[50002] = {};
    likesum[0] = 0;
    rep(i, 50001) likesum[i+1] = likesum[i] + likeP[i]; 
    int Q;
    cin >> Q;
    rep(i, Q) {
        int a, b;
        cin >> a >> b;
        a++; b++;
        a /= 2; b /= 2; 
        //dump(likesum[b+1]); dump(likesum[a]);
        cout << likesum[b+1] - likesum[a] << endl;
    }



    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdlib>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
const int INF = 1 << 29;

int t[1000];
int l[1000];

int main(){
  int n,m;
  while(cin >> n >> m && (n || m)){
    rep(i, n){
      cin >> t[i];
    }
    rep(i, n){
      int least = INF;
      int c = INF;
            
      rep(j, i){
	least = min(least, l[j]);
      }
      rep(j, i){
	if(l[j] == least) c = min(c, t[j]);
      }
      
      int p = m / t[i] * t[i];
      int q = (least + t[i] - 1) / t[i] * t[i];
      int r = min(p, q);
      l[i] = r;
      if(r == least && c > t[i] && r + t[i] <= m) l[i] += t[i];
    }


    int less = INF;
    rep(i, n) less = min(less, l[i]);
    int cnt = 0, id;
    rep(i, n){
      if(l[i] == less) cnt++, id = i;
    }
    if(cnt == 1) {
      cout << id + 1 << endl;
    }else{
      cnt = 0;
      id = 0;
      int dif = INF;
      rep(i, n){
	if(l[i] == less) dif = min(dif, t[i]);
      }
      rep(i, n){
	if(l[i] == less && dif == t[i]) cnt++, id = i;;
      }
      if(cnt== 1){
	cout << id + 1 << endl;
      }else{
	cout << n  << endl;
      }
    }
  }
  return 0;
}

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

int main() {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int ans = (H2 - H1) * 60;
    ans += (M2 - M1);
    ans -= K;

    cout << ans << endl;
}


Measured memory_bytes: 3620