akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(long long int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)
 
int main(){
  int m, n; cin >> n >> m;
  vector<int> a(n);
  REP(i,n){ cin >> a[i];}
  int sum =  std::accumulate(a.begin(), a.end(), 0);
  double thr = (double)sum/(4.0*m);
  int count = 0;
  REP(i,n){
    if( (double)a[i] >= thr ){ count++; }
  }
 
  if(m <= count){ cout << "Yes" << endl; }
  else{ cout << "No" << endl; }
  return 0;
 }

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

int main() {
	// your code goes here
	long long int A,B,K,a,b;
  	cin>>A>>B>>K;
  	
  	if(K>=A)
  	{
  	    K=K-A;
  	    A=0;
  	}
  	else
  	{
  	    A=A-K;
  	    K=0;
  	}
  	if(K>=B)
  	{
  	    K=K-B;
  	    B=0;
  	}
  	else
  	{
  	    B=B-K;
  	    K=0;
  	}
  	
  	cout<<A<<" "<<B<<endl;
	return 0;
}


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


int main() {
  long long int N;
  cin >> N;
  long long int K;
  cin >> K;
  vector<long long int>Length(N);
  int AnsUe = 1000000000;
  int AnsShita = 1;
  int Kaisu = 0;
  
  for(int i=0; i<N; i++){
    cin >> Length.at(i);
    }
  
  while(AnsUe != AnsShita){
    Kaisu=0;
    for(int i=0; i<N; i++){
      Kaisu = Kaisu + (Length.at(i)-1)/((AnsUe+AnsShita)/2);
      }

      if(Kaisu<=K){
        AnsUe=(AnsUe+AnsShita+1)/2;
      }
      else{
        AnsShita=(AnsUe+AnsShita-1)/2;
      }
   if(AnsUe < AnsShita+3){
     break;
   }
  }
  
  while(1==1){
    Kaisu=0;
    for(int i=0; i<N; i++){
      Kaisu = Kaisu + (Length.at(i)-1)/AnsShita;
      }

      if(Kaisu>K){
        AnsShita++;
      }
      if(Kaisu<=K){
        break;
      }
  }
  

    cout << AnsShita;
  
}

Measured memory_bytes: 4752
#include <stdio.h>

int main()
{
    int a, b;
    char ans;
    scanf("%d %d", &a, &b);
    if(a != 1 || b != 1){
        if(a % 2 == 0){
            printf("No");

        } else if(b % 2 == 0){
            printf("No");
        } else{
            printf("Yes");
        }
    } else {
        printf("Yes");
    }
    return 0;
}


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

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

	map<string, int> S;
	S["AC"] = 0;
	S["WA"] = 0;
	S["TLE"] = 0;
	S["RE"] = 0;

	string x;
	for (int i = 0; i < N; i++) {
		cin >> x;
		S[x]++;
	}

	cout << "AC x " << S["AC"] << endl;
	cout << "WA x " << S["WA"] << endl;
	cout << "TLE x " << S["TLE"] << endl;
	cout << "RE x " << S["RE"] << endl;

	return 0;
}

Measured memory_bytes: 3228
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    A,B,C = (int(_) for _ in input().split())
    if A == B:
        print(C)
    elif A == C:
        print(B)
    else:
        print(A)
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
	
	public static void main (String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int minj = 0;
		int A[] = new int[N];
		int count = 0;
		int tmp = 0;
		
		for(int i=0; i<N; i++){
			A[i] = sc.nextInt();
		}
		
		for(int i=0; i<N; i++){
			minj = i;
			for(int j=i; j<N; j++){
				if(A[j] < A[minj]){
					minj = j;
				}
			}
			if(A[i]!=A[minj]){
				tmp = A[i];
				A[i] = A[minj];
				A[minj] = tmp;
				count++;
			}
		}
		for(int i=0; i<N; i++){
			if(i<N-1){
				System.out.print(A[i] + " ");
			}else{
				System.out.println(A[i]);
			}
		}
		System.out.println(count);
	}
}



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


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //

#define int               long long
#define endl              '\n'
#define ff                first
#define ss                second
#define mp                make_pair
#define pb                push_back
#define vii               vector<int> 
#define pii               pair<int,int>
#define vpii              vector< pii >
#define all(v)            v.begin(),v.end()
#define loop(i,s,e)       for(int i=s;i<e;i++)
#define rloop(i,e,s)      for(int i=e;i>=s;i--)
#define mset(a,f)              memset(a,f,sizeof(a))
#define M                 1000000007
#define fastio            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define prvec(v)          loop(i_u_j,0,v.size())cout << v[i_u_j] <<" "; cout << endl;
#define prarr(arr,n)      loop(i_u_j,0,n)cout << arr[i_u_j] << " "; cout << endl;
#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)


template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //
const int N = 107;
int n;
int wt[N], val[N], dp[N][100007];

int getval(int it, int mxw)
{     
      if( dp[it][mxw] != -1 ) return dp[it][mxw];
      
      if( mxw == 0 || it == n ) return dp[it][mxw] = 0;
      int a = 0, b = 0;
      if( wt[it] <= mxw )
      {
            a = val[it] + getval(it+1, mxw - wt[it]);
      }
      b = getval(it+1, mxw);
      return dp[it][mxw] = max(a, b);
}
void solve()
{     
      int mxw;
      cin >> n >> mxw;
      loop(i,0,n)
      {
            cin >> wt[i] >> val[i];
      }
      mset(dp,-1);
      cout << getval(0,mxw);
}

int32_t main() {
    fastio;
// #ifndef ONLINE_JUDGE
//     freopen("input.txt",  "r",  stdin);
//     freopen("output.txt", "w", stdout);
//  #endif
  
  int t = 1; 
  //cin>>t;
  
  while(t--) solve();
  
  


}


// M A F I A - M A F I A - M A F I A - M A F I A - M A F I A - M A F I A //















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

int main(){
  while(true){
    int N, M, temp[110] = {}, d, v ,sum = 0;
    cin>>N>>M;

    if(!N&&!M) break;

    for(int i = 1; i <= N; i++){
      cin>>d>>v;
      temp[d] = max(temp[d], v);
    }

    for(int i = 1; i <= M; i++){
      sum += temp[i];
    }
    cout<<sum<<endl;

  }
  return 0;
}



Measured memory_bytes: 3092
def solve(s):
    one = 0
    zero = 0
    for i in range(len(s)):
        if s[i] == "1":
            one += 1
        elif s[i] == "0":
            zero += 1
    return min(zero, one)


def main():
    S = input()
    # a, b, k = [int(a) for a in input().split()]

    print(solve(S) * 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#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 K, X;
    cin >> K >> X;

    for (int i = X - K + 1; i <= X + K - 1; i++) {
        if (i < -1000000) {
            continue;
        }
        if (i > 1000000) {
            break;
        }

        printf("%d%c", i, i == X + K - 1 || i == 1000000 ? '\n' : ' ');
    }

    // 出力
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int n,m; 
int a,b;
Pair p[100010];
int main(){
    cin >> n >> m;
    bool bridge[n];
    for(int i = 0; i < n-1; i++){
        bridge[i] = true;
    }
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        a--; b--;
        p[i] = make_pair(b,a);
    }
    sort(p,p+m);
    for(int i = 0; i < m; i++){
        bool tmp = true;
        for(int j = p[i].second; j < p[i].first; j++){
            if(bridge[j] == false){
                tmp = false;
                break;
            }
        }
        if(tmp) bridge[p[i].first-1] = false;
    }
    int ans = 0;
    for(int i = 0; i < n-1; i++){
        if(!bridge[i]){
            ans++;
        }
    }
    cout << endl;
    cout << ans << endl;
}

 

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0;i <n;i++)
#define RFOR(i, n) for(int i = n;i >= 0;i--)
#define REP(i, m, n) for(int i = m;i < n;i++)
#define RREP(i, m, n) for(int i = m;i >= n;i--)
using namespace std;
int main(int argc, char const *argv[])
{
 string s;
 cin >>s;
 int i,j,n;
 int flag =0;
 n = s.size();
 if(s[0] == 'A')
{
   REP(i,2,n-1)
   {
     if(s[i] == 'C')
     flag++;
   }

   if(flag > 1 || flag == 0)
   {
     cout<<"WA"<<endl;
     return 0;
   }

    flag = 0;

    FOR(i,n)
    {
      if('A' <= s[i]&&s[i] <= 'Z')
        flag++;

    }

    if(flag == 2)
    {
      cout<<"AC"<<endl;
      return 0;
    }
    else
    {
      cout<<"WA"<<endl;
      return 0;
    }

} else
 {
   cout<<"WA"<<endl;
   return 0;
 }

 }



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


int dp[100'000+5][3];      /// dp[i][j] = max total reward in first i days,
                           /// where j-th activity was done in last day

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

    int n;
    cin>>n;
    vector<int> A(n), B(n), C(n);

    for(int i = 0; i<n; i++){
        cin>>A[i]>>B[i]>>C[i];
    }

    dp[0][0] = A[0];
    dp[0][1] = B[0];
    dp[0][2] = C[0];

    for(int i = 1; i<n; i++){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + A[i];

        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + B[i];

        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + C[i];
    }

    int ans = max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});

    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 5552
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)

int main(){ FastIO;

string s;cin>>s;
if(s[0]=='7' || s[1]=='7' || s[2]=='7') cout<<"Yes";
else cout<<"No";

return 0;
}


Measured memory_bytes: 3648
import java.io.PrintWriter
import java.util

object Main {


  def main(args: Array[String]) {
    val stdin = scala.io.StdIn

    val printWriter = new PrintWriter(System.out)

    val a = stdin.readLine().split(" ").map(i => i.toInt)

    printWriter.println(Math.min(a(1) / a(0), a(2)))

    printWriter.close()
  }
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ll dp[200010][4];

void solve() {
    ll N;
    cin >> N;
    Vl A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), -L_INF);

    dp[0][0] = 0;
    dp[1][0] = A[0];

    ll lm;
    if (N & 1)
        lm = 2;
    else
        lm = 1;

    for (ll i = 1; i <= N; i++) {
        for (ll j = 0; j <= lm; j++) {
            for (ll k = 0; k <= 2; k++) {
                if (i - (2 + k) >= 0 && j - k >= 0 && dp[i - (2 + k)][j - k] != -L_INF) {
                    dp[i][j] = max(dp[i][j], dp[i - (2 + k)][j - k] + A[i - 1]);
                }
            }
        }
    }

    ll ans = -L_INF;
    if (N & 1) {
        ans = max(ans, dp[N - 2][0]);
        ans = max(ans, dp[N - 1][0]);
        ans = max(ans, dp[N - 1][1]);
        ans = max(ans, dp[N][1]);
        ans = max(ans, dp[N][2]);
    }
    else {
        ans = max(ans, dp[N - 1][0]);
        ans = max(ans, dp[N][0]);
        ans = max(ans, dp[N][1]);
    }

    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 11100
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		List<Integer> list = new ArrayList<>();
		for (int i = 6; i <= N; i *= 6)
			list.add(i);
		for (int i = 9; i <= N; i *= 9)
			list.add(i);
		Collections.sort(list);

		int[] dp = new int[N + 1];
		for (int i = 1; i < dp.length; i++)
			dp[i] = i;
		for (int m : list)
			for (int i = m; i < dp.length; i++)
				if (dp[i] > dp[i - m] + 1)
					dp[i] = dp[i - m] + 1;
		System.out.println(dp[N]);
	}
}


Measured memory_bytes: 23124
use itertools::Itertools;
use itertools_num::ItertoolsNum;
use proconio::input;
use std;

fn fac(x: usize) -> usize {
    match x {
        1 => 1,
        _ => fac(x - 1) * x,
    }
}

fn dist(v1: (f64, f64), v2: (f64, f64)) -> f64 {
    ((v1.0 - v2.0) * (v1.0 - v2.0) + (v1.1 - v2.1) * (v1.1 - v2.1)).sqrt()
}

fn main() {
    input! {
        n: usize,
        xy:[(f64, f64); n]
    }

    let mut sum = 0f64;
    for idx in (0..n).permutations(n) {
        for i in 1..n {
            sum += dist(xy[idx[i]], xy[idx[i - 1]]);
        }
    }

    println!("{}", sum / (fac(n) as f64));
}


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

int main()
{
	int k;
    cin >> k;
    if(k%2==0)
    {
        cout << -1 << endl;
    }
    else
    {
		set<int> s;
    
        int cnt7 = 0;
        int num = 0;
        for(int i = 0; i <= 2* k; i++)
        {
            cnt7++;
            num = num *10 + 7;
            if(num%k == 0) 
            {
                cout << cnt7 << endl;
                break;
            }
            else
            {
                int rem = num%k;
                
                if(s.find(rem) == s.end())
                	s.insert(rem);
                else
                {
                    cout << -1 << endl;
                    break;
                }
                
                num = rem;
            }
        }
    }
    
	return 0;
}

Measured memory_bytes: 50456
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, b, c, d, e;std::cin >> a >> b >> c >> d >> e;
  ll t = max((ll)0, (c-a)*60 + (d-b));
  std::cout << max((ll)0, t-e) << '\n';
  return 0;
}


Measured memory_bytes: 3192
N = int(input())

res = 0

for i in range(1, N + 1):
    if i % 3 == 0 and i % 5 == 0:
        continue
    elif i % 3 == 0:
        continue
    elif i % 5 == 0:
        continue
    else:
        res += i

print(res)

Measured memory_bytes: 9168
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; 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 N; cin >> N;
    int C[510], S[510], F[510];
    for(int i = 0; i < N - 1; i++) {
        cin >> C[i] >> S[i] >> F[i];
    }
    for (int i = 0; i < N - 1; i++) {
        int Gt = 0; // 到着時間
        for(int j = i; j < N - 1; j++) {
            Gt = max(Gt, S[j]);
            Gt += (F[j] - Gt % F[j]) % F[j];
            Gt += C[j];
            //cout << j << " " << Gt << endl;
        }
        cout << Gt << endl;
    }
    cout << 0 << endl;

    return 0;
}


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

int main(){
    int N,M,ans;
  	cin >> N >> M;
    int l=1;
    int r=N;
    for(int i=0;i<M;i++){
        int ifl,ifr;
        cin >> ifl >> ifr;
        l = max(l,ifl);
        r = min(r,ifr);
    }
  	if(r-l+1>=0){
      ans = r-l+1;
    }
  	else{
      ans = 0;
    }
    cout <<ans<< endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
const double PI = acos(-1.0);
const string ALP = "abcdefghijklmnopqrstuvwxyz";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int main(){
  int h,w;
  string s;
  cin >> h >> w;
  REP(i,w+2)cout << "#";
  cout << endl;
  REP(i,h){
    cout << "#";
    cin >> s;
    cout << s;
    cout << "#" << endl;
  }
  REP(i,w+2)cout << "#";
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n, a, b = map(int,input().split(' '))

if n <= a:
    print(n)
else:
    ans = (n//(a+b))*a
    m = n%(a+b)
    if m >= a:
        ans += a
    else:
        ans += m

    print(ans)

Measured memory_bytes: 2940
a,b,c,x,y = map(int,input().split())

ans = 0
if x >= y:
  if (a+b) >= 2*c:
    ans = min(2*c*y + a*(x-y),2*c*x)
  
  else:
    ans = a*x + b*y
    
else:
  if(a+b) >= 2*c:
    ans = min(2*c*x + b*(y-x),2*c*y)
  else:
    ans = a*x + b*y
    
print(ans)

Measured memory_bytes: 3064
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
c = input()
if c in "aiueo":
    print("vowel")
else:
    print("consonant")
#B

#C
"""
s = input()
while s:
    if s[:11] == "dreameraser":
        s = s[11:]
    elif s[:10] == "dreamerase":
        s = s[10:]
    elif s[:7] == "dreamer":
        s = s[7:]
    elif s[:6] == "eraser":
        s = s[6:]
    elif s[:5] == "dream":
        s = s[5:]
    elif s[:5] == "erase":
        s = s[5:]
    else:
        print("NO")
        quit()
print("YES")
"""

#D
"""
def root(x,par,rank):
    if x == par[x]:
        return x
    par[x] = root(par[x],par,rank)
    return par[x]
def unite(x,y,par,rank):
    x = root(x,par,rank)
    y = root(y,par,rank)
    if x == y:return
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1
n,k,l = LI()
par1 = [i for i in range(n)]
rank1 = [0 for i in range(n)]
par2 = [i for i in range(n)]
rank2 = [0 for i in range(n)]
for i in range(k):
    p,q = LI()
    p -= 1
    q -= 1
    unite(p,q,par1,rank1)
for i in range(l):
    p,q = LI()
    p -= 1
    q -= 1
    unite(p,q,par2,rank2)
d = {}
for i in range(n):
    k = (root(i,par1,rank1),root(i,par2,rank2))
    if k in d:
        d[k] += 1
    else:
        d[k] = 1
ans = []
for i in range(n):
    k = (root(i,par1,rank1),root(i,par2,rank2))
    ans.append(d[k])
print(*ans)
"""

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


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


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	if (c - (a + b) > 0) {
		cout << 2 * b + a + 1 << endl;
	}
	else {
      cout << b + c << endl;
    }
}


Measured memory_bytes: 256
n = int(input())
s =set()

for _ in range(n):
    s.add(int(input()))

ls = list(s)

from fractions import gcd
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list(ls))


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

int main(){
    ll n; //カードの枚数
    ll m; //ゲートの個数
    cin >> n >> m;

    vector<ll> count(n);
    ll l,r; cin >> l >> r;
    ll L = l;
    ll R = r;
    for(int i=0; i<m-1; i++){
        cin >> l >> r;
        L = max(L,l);
        R = min(R,r);
    }

    ll ans = R-L+1;

    if(ans < 0) ans = 0;

    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {

		long a = sc.nextLong(); long b = sc.nextLong(); long c = sc.nextLong();
		if (a%2==0 || b%2==0 || c%2==0) {
			System.out.println(0);
		}
		else {
			System.out.println(Math.min(a*b,Math.min( b*c, c*a)));
		}

	}
	}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
    #include <set>
    #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 SORT(v, n) sort(v, v+n);
    #define VSORT(v) sort(v.begin(), v.end());
    //
    #define llong long long
    #define pb(a) push_back(a)

    #define INF 100000000
    #define MOD 1000000007

    #define writeln(n) cout<<n<<endl

    using namespace std;
    typedef pair<int, int> P;
    typedef pair<llong, llong> LP;
    typedef pair<int, P> PP;
    typedef pair<llong, LP> LPP;
    //vector<tuple<long long, long long, long long>>vec;

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

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

    llong pownew(llong m, llong n) {
        if (n == 0) { return 1; }
        if (n % 2 == 0) { return pow(m*m, n/2); }
        return pow(m, n-1) * m;
    }

    bool isprime(int p) {
        if (p == 1) return false;
        for (int i = 2; i < p; i++) {
            if (p%i == 0) return false;
        }
        return true;
    }

    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};

    const int inf=100000000;

    long long modpow(long long a, long long n, long long mod) //a^n
    {
        long long res = 1;
        while (n > 0) {
            if (n & 1) res = res * a % mod;
            a = a * a % mod;
            n >>= 1;
        }
        return res;
    }

    int gcd(int a, int b) {
        return b != 0 ? gcd(b, a % b) : a;
    }
    //setprecision(10);

    typedef long long ll;

    ll merge_cnt(vector<int> &a) {
        int n = a.size();
        if (n <= 1) { return 0; }

        ll cnt = 0;
        vector<int> b(a.begin(), a.begin()+n/2);
        vector<int> c(a.begin()+n/2, a.end());

        cnt += merge_cnt(b);
        cnt += merge_cnt(c);

        int ai = 0, bi = 0, ci = 0;
        // merge の処理
        while (ai < n) {
            if ( bi < b.size() && (ci == c.size() || b[bi] <= c[ci]) ) {
                a[ai++] = b[bi++];
            } else {
                cnt += n / 2 - bi;
                a[ai++] = c[ci++];
            }
        }
        return cnt;
    }


    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n; cin>>n;
        vector<int> b(n,0);
        REP(i,n) cin>>b[i];
        int ans=0;
        if(n==2)
        {
            ans=b[0]+b[0];
        }
        else if(n==3)
        {
            ans=b[0]+b[0]+b[1];
        }
        else
            {
                REP(i,n-2)
                {
                    ans+=min(b[i],b[i+1]);
                }
                ans+=(b[0]+b[n-2]);
            }

        cout<<ans<<endl;

        return  0;
    }


Measured memory_bytes: 256
import math

prime = [2]
max = 10 ** 5
limit = int(math.sqrt(max))
data = [i + 1 for i in range(2, max, 2)]

while limit > data[0]:
    prime.append(data[0])
    data = [j for j in data if j % data[0] != 0]
prime = prime + data

lista = [0] * max
for i in prime:
    if (i + 1) / 2 in prime:
        lista[i - 1] = 1

listb = [0]
for i in range(max):
    listb.append(lista[i] + listb[i])

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(listb[r] - listb[l - 1])

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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

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

const int N = 2e3 + 5, M = 4e6 + 5;

int DP[N][N], F[M], I[M];

int Power(int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = 1LL * a * a % MOD) if (b & 1) res = 1LL * res * a % MOD;
	return res;
}
int C(int n, int r) { return r > n ? 0 : 1LL * I[r] * I[n - r] % MOD * F[n] % MOD; }

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	F[0] = 1;
	for (int i = 1; i < M; i++) F[i] = 1LL * i * F[i - 1] % MOD;
	I[M - 1] = Power(F[M - 1], MOD - 2);
	for (int i = M - 2; i >= 0; i--) I[i] = 1LL * (i + 1) * I[i + 1] % MOD;
	
	int n, k; cin >> n >> k;
	if (k == 1) die(1);
	DP[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		DP[i][0] = 1LL * DP[i - 1][0] * C(i * (k - 1) - 1, k - 2) % MOD;
		for (int j = 1; j <= i; j++) DP[i][j] = (DP[i][j - 1] + 1LL * DP[i - 1][j] * C(i * (k - 1) + j - 1, k - 2) % MOD) % MOD;
	}
	cout << 1LL * DP[n][n] * F[n] % MOD << endl;

	return 0;
}


Measured memory_bytes: 47232
#include<bits/stdc++.h>
using namespace std;
unsigned int n,a[1000005]={0,1,2,3,4,5,6,7,8,9};
int head=1,tail=10;
int main()
{
	scanf("%d",&n);
	while(tail<=n)
	{
		//printf("%d ",head);
		int tmp=a[head]%10;
		if(tmp!=0)
		{
			a[tail]=a[head]*10+tmp-1;
			tail++;
		}
		a[tail]=a[head]*10+tmp;
		tail++;
		if(tmp!=9)
		{
			a[tail]=a[head]*10+tmp+1;
			tail++;
		}
		head++;
	}
	//puts("");
	//for(int i=1;i<n;i++)
	//	printf("%d ",a[i]);
	printf("%u",a[n]);
    return 0;
}

Measured memory_bytes: 640
def showSeq(seq):
  for i in range(len(seq)):
    if i<len(seq)-1: # 最后一个元素的下标为 len(seq)-1
      print(seq[i],end=' ')
    else:
      print(seq[i])
      
      
n = input()
list1 = list(map(int,input().split()))
count = 0

for i in range(len(list1)-1):
  for j in range(len(list1)-1,i,-1):
    if list1[j]<list1[j-1]:
      list1[j],list1[j-1] = list1[j-1],list1[j] 
      # python中的变量保存的是变量值所在的地址； 例如 a=5;b=5 a和b指向内存中同一个地址 id(a) == id(b)
      count+=1
showSeq(list1)
print(count)



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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}


int H, W, K;
string s[810];
int memo[810][810];

const int INF = 1001001001;
const int dr[] = {0, 1, 0, -1};
const int dc[] = {1, 0, -1, 0};

void bfs(int r, int c, int walk) {
  REP(i, H) REP(j, W) memo[i][j] = INF;
  memo[r][c] = 0;
  queue<int> q;
  q.push(r); q.push(c);
  while (q.size() > 0) {
    r = q.front(); q.pop();
    c = q.front(); q.pop();
    if (memo[r][c] == walk) break;
    for (int i = 0; i < 4; i++) {
      int nr = r + dr[i];
      int nc = c + dc[i];
      if (0 <= nr && nr < H && 0 <= nc && nc < W && s[nr][nc] == '.' && memo[nr][nc] == INF) {
        memo[nr][nc] = memo[r][c] + 1;
        q.push(nr);
        q.push(nc);
      }
    }
  }
}

int ceil(int r, int x) {
  return (r + x - 1) / x;
}

int f(int r, int c) {
  if (r == 0 || c == 0 || r == H - 1 || c == W - 1) return 0;
  return min({
    ceil(r, K),
    ceil(H - 1 - r, K),
    ceil(c, K),
    ceil(W - 1 - c, K)});
}

int main2() {
  cin >> H >> W >> K;
  REP(i, H) cin >> s[i];

  int si = 0, sj = 0;
  REP(i, H) REP(j, W) if (s[i][j] == 'S') {
    si = i; sj = j; s[i][j] = '.'; break;
  }
  bfs(si, sj, K);

  int ans = INF;
  REP(i, H) REP(j, W) {
    if (memo[i][j] <= K) {
      chmin(ans, f(i, j) + 1);
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 3712
#author : dokueki

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    n, m = map(int, sys.stdin.readline().split())
    a = list(map(int, sys.stdin.readline().split()))
    s = sum(a)
    need = s / (4*m)
    cnt = []
    for i in a:
        if i >= need:
            cnt.append(i)
    if len(cnt) >= m:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()


Measured memory_bytes: 38256
#include<stdio.h>
int main() {
    int a;
    scanf("%d", &a);
    int s = a % 60;
    int m = ((a - s) % 3600) / 60;
    int h = (a - s - m) / 3600;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}


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

int main(){
  long n,mi,ze,sum,li,lit;
  sum=0;
  cin >> n;
  vector<long> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    if(vec.at(i)<0){
      mi++;
      vec.at(i)=-vec.at(i);
    }
    else if(vec.at(i)==0){
      ze==1;
    }
  }
  li=vec.at(1);
  lit=1;
  if(ze==1){
    for (int j = 0; j < n; j++){
      sum += vec.at(j);
    }
  }
  else if(mi%2==0){
    for (int j = 0; j < n; j++){
      sum += vec.at(j);
    }
  }
  else if(mi%2==1){
    for (int j = 0; j < n; j++){
      if(vec.at(j)<li){
        li=vec.at(j);
        lit=j;
      }
    }
    vec.at(lit)=-vec.at(lit);
    for (int j = 0; j < n; j++){
      sum += vec.at(j);
    }
  }
  cout << sum << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 1), B(N);
    for (int &a : A) cin >> a;
    for (int &b : B) cin >> b;
    
    long ans = 0;
    for (int i = 0; i < N; i++) {
        int tmp = min(A.at(i), B.at(i));
        A.at(i) -= tmp;
        B.at(i) -= tmp;
        ans += tmp;
        int tmp2 = min(A.at(i + 1), B.at(i));
        A.at(i + 1) -= tmp2;
        B.at(i) -= tmp2;
        ans += tmp2;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define DAU  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int N, M;
int main() {
    DAU
    cin >> N >> M;
    vector<pair<int,char>> V(M);
	for(int i=0;i<M;i++)cin>>V[i].first>>V[i].second;

	for(int i=0;i<1000;i++){
		string t = to_string(i);
		if(t.size()!=N)continue;
		bool f = true;
		for(int j=0;j<M;j++){
			if(t[V[j].first-1]!=V[j].second){
				f=false;
				break;
			}
		}
		if(f){
			cout<<i<<endl;
			return 0;
		}
	}

	cout<<-1<<endl;
    PLEC
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FIN freopen("E:/in.txt", "r", stdin)
using namespace std;
const int maxn = 1e5+5;
int a[maxn];
struct node{
    int num, cnt;
    bool operator < (const node & b){
        return cnt > b.cnt;
    }
}ll[maxn], rr[maxn];
map<int, int> l, r;
int main(){
    //FIN;
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
        if(i&1) l[a[i]]++;
        else r[a[i]]++;
    }
    map<int, int>::iterator it1;
    int index_a = 0, index_b = 0;
    for(it1 = l.begin(); it1 != l.end(); it1++) ll[index_a].num = it1->first, ll[index_a++].cnt = it1->second;
    for(it1 = r.begin(); it1 != r.end(); it1++) rr[index_b].num = it1->first, rr[index_b++].cnt = it1->second;
    sort(ll, ll+index_a);
    sort(rr, rr+index_b);
    if(ll[0].num != rr[0].num){
        printf("%d\n", n-ll[0].cnt-rr[0].cnt);
    }
    else{
        int ans = 0;
        if(index_a > 1) ans = ll[1].cnt + rr[0].cnt;
        else ans = rr[0].cnt;
        if(index_b > 1) ans = max(ans, ll[0].cnt + rr[1].cnt);
        else ans = max(ans, ll[0].cnt);
        printf("%d\n", n-ans);
    }
    return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	ll x;
	cin >> x;
	for(int a = -118; a < 120; a++) {
		for(int b = -119; b < 119; b++) {
			if(pow(a,5)-pow(b,5) == x) {
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}

	return 0;
}



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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long a, b;
    cin >> a >> b;
    for(long long i = b - a + 1; i <= b + a - 1; i++)
    {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define sz(x) int(x.size())
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define SIZE 26     
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
 
const ll mod = 1e9 + 7;
const int inf = 1e9 + 5;
const int N = 1e5 + 5;

int dp[N][3],a[N],b[N],c[N];

signed main(){
    fastio;
    int i,j,n;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    for(i=1;i<=n;i++){
        dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
        dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
        dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
    }
    cout<<max({dp[n][0],dp[n][1],dp[n][2]});
    return 0;
}

Measured memory_bytes: 2560
import math

a, b, h, m = map(int, input().split())
ji_kaku = 30 * h + 0.5 * m
hun_kaku = 6 * m
sa1 = ji_kaku - hun_kaku
sa2 = hun_kaku + (360 - ji_kaku)
sa = min(sa1, sa2)

resres = (a * a) + (b * b) - (2 * a * b * math.cos(math.radians(sa)))
res = math.sqrt(resres)

print(abs(res))

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

using namespace std;


#define PI 3.14159265
#define int long long



main(){


	string s; cin >> s;


	int cnt = 0, n = s.size();

	for(int i = 0, j = n - 1; i < j; i++, j--){
		if(s[i] != s[j]) cnt++;
	}


	cout << cnt << endl;

	return 0;
}

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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/

#define ff first
#define ss second
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define endl            "\n"
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY 1
#define BLACK 2

int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/

const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;


typedef long long ll;
const ll inf = 5e18+100;
typedef unsigned long long ull;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;
typedef vector<int> vi;
int n, k, a[maxn];
ll DP[maxn];

ll cal(int pos){

	if(pos==n-1) return 0LL;

	ll &ret = DP[pos];
	if(ret !=-1) return ret;

	ret = 0LL;

	ret = abs(a[pos]-a[pos+1])+cal(pos+1);
	for(int i=2 ; i<=k ; i++){
		if(pos+i<n){
			ret = min(ret, abs(a[pos]-a[pos+i])+cal(pos+i));
		}
	}
	return ret;
}

void solve(){

	cin >> n >> k;
	f0(i,n){
		cin >> a[i];
	}

	memset(DP, -1 , sizeof(DP));

	cout << cal(0) << endl;

    return;
}

int main()
{
    CIN

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    //cout << "Fi Amanillah" << endl;

    int t = 1;
    //cin >> t;

    while(t--){
        solve();
    }

    return 0;
}

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

#define NL '\n'
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define ones __builtin_popcount
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%I64d",&x)
#define sd(x) scanf("%lf",&x)
#define ss(x) scanf("%s",x)
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define REV(i,j,k) for(int i=j;i>=k;i--)
#define READ(f) freopen(f,"r",stdin)
#define WRITE(f) freopen(f,"w",stdout)
#define debug(x) cerr << "debug = " << x << "\n";
#define debugs(s,x) cerr << "debug : " << s << " = " << x << "\n";
#define cnd tree[idx]
#define lnd tree[idx*2]
#define rnd tree[(idx*2)+1]
#define lndp (idx*2),(b),((b+e)/2)
#define rndp (idx*2+1),((b+e)/2+1),(e)
#define X real()
#define Y imag()
#define Point complex<long double>
#define pi 2.0*acos(0.0)
#define EPS 1e-9
#define INF INT_MAX
#define MOD 1000000007
#define MAX 100005

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;


int mod(string num, int a)
{
    // Initialize result
    int res = 0;

    // One by one process all digits of 'num'
    for (int i = 0; i < num.length(); i++)
         res = (res*10 + (int)num[i] - '0') %a;

    return res;
}

int main()
{
    //READ("input.txt");
    //WRITE("out.txt");
    //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    //uniform_int_distribution<int>(0, 10000)(rng)
    std::ios_base::sync_with_stdio(0);
char c;
cin>>c;
c=c+1;
cout<<c<<endl;



    return 0;
}





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

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int w=fsc.nextInt();
        int a=fsc.nextInt(), b=fsc.nextInt();
        fsc.close();
        if(a<=b && b<=a+w) System.out.println(0);
        else if(a<=b+w && b+w<=a+w) System.out.println(0);
        else if(a+w<=b) System.out.println((b-a-w));
        else System.out.println((a-b-w));
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


Measured memory_bytes: 21076
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,all,all1,all2;
    cin>>a>>b>>c;
    all=a+b;
    all1=b+c;
    all2=a+c;
    for (int i=0; i<1; i++)
    {
        if (all<=all1 && all<=all2)
        {
            cout<<all;
            break;
        }
        if (all1<=all && all1<=all2)
        {
            cout<<all1;
            break;
        }
        if (all2<=all1 && all2<=all)
        {
            cout<<all2;
            break;
        }
    }
   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >> x;
  vector<int> arr(x);
  for (int i = 0; i<x; i++){
    cin >> arr[i];
  }
  vector<vector<int> > B(1);
  for (int i = 0; i<x; i++){
    if (B.back().size() == 0){
      B.back().push_back(arr[i]);
    } else if (B.back().size() == 1){
      B.back().push_back(arr[i]);
    } else if (B.back().front() == B.back().back()){
      B.back().push_back(arr[i]);
    } else if (B.back().front() < B.back().back()){
      if (B.back().back() <= arr[i]){
        B.back().push_back(arr[i]);
      } else {
        B.push_back(vector<int>(1, arr[i]));
      }
    } else {
      assert(B.back().front()>B.back().back());
      if (B.back().back() >= arr[i]){
        B.back().push_back(arr[i]);
      } else {
        B.push_back(vector<int>(1, arr[i]));
      }
    }
  }
  cout << B.size();
    return 0;
}


Measured memory_bytes: 6296
# dp[i][j]=(i番目まで使って最後の高さがjであるようなものの美しさの最大値)
# dp[i][j]=max(dp[i-1][k])+a[i](h[i]==j,0<=k<j),dp[i-1][j](otherwise)

def segfunc(x,y):
    return max(x,y)


def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res


N=int(input())
h=list(map(int,input().split()))
a=list(map(int,input().split()))
n=N+1
#####単位元######
ide_ele = 0 #変える
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num
dp=[0]*n
init(dp)
for i in range(N):
    # dp[h[i]]の値をdp[k](kは[0,h[i]))の最大値+a[i]にする
    # 手で書いてみると動きがわかりやすい
    update(h[i],query(0,h[i])+a[i])
print(query(0,n))

Measured memory_bytes: 123728