akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

int main() {
  int n, ch;
  cin >> n >> ch;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i ++) cin >> a[i] >> b[i] >> c[i];

  vector<int> sum(200000 + 2, 0);
  for (int i = 1; i <= ch; i ++) {
    vector<int> t(200000 + 2, 0);
    for (int j = 0; j < n; j ++) {
      if (c[j] == i) t[2 * (a[j] - 0.5)] ++, t[2 * b[j]] --;
    }
    for (int j = 1; j < 200002; j ++) t[j] += t[j - 1];
    for (int j = 0; j < 200002; j ++) {
      if (t[j] > 0) sum[j] ++;
    }
  }

  int ans = 0;
  for (int i = 1; i < 200002; i ++) ans = max(ans, sum[i]);

  cout << ans << endl;
}

Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	string a; 
	string b; 
	cin >> b; 
	for (int i = 0; i < b.size(); i++)
	{
		if (b[i]!='B') {
			 
			a += b[i];
		} 
		else if (b[i]=='B'&&a.size())
		{
			a.pop_back();
		}
	} 
	cout << a << "\n";
} 


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


void solve(long long N){
    cout << (N%2==0 ? N : 2*N) << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int ans[100100];
int tmp[100100];

signed main() {

    string s;

    cin >> s;

    vector<int> v;

    for(int i = 0; i < s.size()-1; i++) {
        if(s[i] == 'R' and s[i+1] == 'L') v.bash(i);
    }
    
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'R') {
            int t = *lower_bound(ALL(v), i);
            if((t-i)%2 == 0) tmp[t]++;
            else tmp[t+1]++;
        }
        else {
            int t = v[lower_bound(ALL(v), i) - v.begin() - 1];
            if((t-i)%2==0) tmp[t]++;
            else tmp[t+1]++;
        }
    }

    for(int i = 0; i < s.size(); i++) cout << tmp[i] << " \n"[i+1==s.size()];

  
    return 0;
}



Measured memory_bytes: 1232
w, a, b = map(int, input().split())

if b <= a+w and a+w <= b+w:
    print(0)
elif b <= a and a <= b+w:
    print(0)
else:
    if a+w < b:
        ans = b - (a + w)
        print(ans)
    elif a > b+w:
        ans = a - (b + w)
        print(ans)


Measured memory_bytes: 3060
#include <stdio.h>

int A[1000000], n;

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

int main(void) {
  int i, q, k, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&k);
    if(binarySearch(k))
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}


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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(auto i##0_to = (t), i = decltype(t)(f); i <= i##0_to; i++)
#define uptil(f, t, i)   for(auto i##0_to = (t), i = decltype(t)(f); i <  i##0_to; i++)
#define downto(f, t, i)  for(auto i##0_to = decltype(f)(t), i = (f); i >= i##0_to; i--)
#define downtil(f, t, i) for(auto i##0_to = decltype(f)(t), i = (f); i >  i##0_to; i--)
// types
	using LD = long double;
	#define double LD
	#define long long long
	#define int long
	using VB = vector<bool>;   using WB = vector<VB>;
	using VC = vector<char>;   using WC = vector<VC>;
	using VI = vector<int>;    using WI = vector<VI>;
	using VD = vector<double>; using WD = vector<VD>;
	using VS = vector<string>; using WS = vector<VS>;
	using PI = pair<int, int>;
	using VPI = vector<PI>;    using WPI = vector<VPI>;

bool debug;
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 2
#define _LIBCPP_DEBUG2 2
#define ln << '\n'
#define tb << '\t'
#define sp << ' '
#define db(x) if(debug) cerr << #x << " = " << (x) << ", "
#define dbg(x) if(debug) cerr << #x << " = " << (x) ln

void solve();

signed main(signed argc, char *argv[]) {
	#ifdef EBUG
		debug = true;
	#elif defined(ONLINE_JUDGE)
		debug = false;
	#else
		debug = argc >= 2;
	#endif
	if(!debug) {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);

	solve();

	return 0;
}

/******************************* basic library ********************************/
// IO
	template<class T>
	istream& operator>>(istream& s, vector<T>& v) {
		for(auto&& p : v) s >> p; return s;
	}
	template<class T>
	ostream& operator<<(ostream& s, vector<T> v) {
		int i = 0;
		for(const auto& p : v) s << (i++?" ":"") << p;
		return s;
	}
	template<class T>
	ostream& operator<<(ostream& s, vector<vector<T>> w) {
		for(const auto& v : w) {
			int i = 0;
			for(const auto& p : v) s << (i++?" ":"") << p;
			s ln;
		}
		return s;
	}
	template<class T> T& RD(T& t) { cin >> t; return t; }
	template<class T, class... A> T RD(A... a) { T t(a...); cin >> t; return t; }
// container
	#define all(v) (v).begin(), (v).end()
	template<class T> T max(const pair<T, T>& p) { return max(p.first, p.second); }
	template<class T> T min(const pair<T, T>& p) { return min(p.first, p.second); }
// other
	#define all(v) v.begin(), v.end()
	#define b_max(x, y) x = max(x, y)
	#define b_min(x, y) x = min(x, y)
	inline LD AC(LD d) { return d ? d : 0; }
constexpr long INF = 1LL << 60;
constexpr long MOD = 1000000009; // 1000000007; // 998244353;

/****************************** optional library ******************************/


/************************************ main ************************************/

void solve() {
	int N; cin >> N;
	WI A(2, VI(N)); cin >> A;
	int ans = 0;
	times(N, i) {
		int a = 0;
		upto(0, i, j) a += A[0][j];
		uptil(i, N, j) a += A[1][j];
		ans = max(ans, a);
	}
	cout << ans ln;
}


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

using namespace std;

int main(){
    int x;
    cin>>x;
    int a, b, c, hp;
    a = x/500;
    b = x%500;
    c = b/5;
    hp = (a*1000) + (c*5);
    cout<<hp;
    return 0;
}


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

using namespace std;

int main() {
  string S;
  cin >> S;
  
  if (S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
/**************************************
*Coded By: BadduCoder (Sumit Badsara) *
***************************************/
#include<bits/stdc++.h>
using namespace std;

//All the Loops and defines required
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define ff first
#define ss second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

//All the declarations using typedef

typedef long long int ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef map<int,int> MII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int l;

int main()
{
    _cin;
    ll n,w,Tval=0;
    cin>>n>>w;
    ll val[n],wei[n];
    REP(i,n)
    {
        cin>>wei[i]>>val[i];
        Tval += val[i];
    }

    ll dp[Tval+1];

    REP(i,Tval+1)
        dp[i] = INF;
    
    dp[0] = 0;

    REP(i,n)
        RFOR(j,Tval,val[i],1)
            dp[j] = min(dp[j],dp[j-val[i]]+wei[i]);

    RFOR(i,Tval,0,1)
    {
        if(dp[i]<=w)
        {
            cout<<i;
            break;
        }
    }

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n,0);
    rep(i, n){
        cin >> a.at(i);
    }
    ll sum=0;
    vector<ll> b(n-1,0);
    rep(i, n-1){
        if(i==0){
          b.at(n-2-i)=a.at(n-1-i);
        } else {
          b.at(n-2-i)=b.at(n-1-i)+a.at(n-1-i);
        }
         b.at(n-2-i)%=1000000007;
    }

    rep(i, n-1){
        sum+=a.at(i)*b.at(i);
        sum%=1000000007;
    }
    cout << sum << endl;
}


Measured memory_bytes: 6336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, a[100005], sum[100005];

int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) {
		scanf("%lld",&a[i]);
	}
	sort(a+1, a+1+n);
	for(int i=1;i<=n;i++) {
		sum[i] = sum[i-1] + a[i];
	}
	for(int i=n-1;i>=1;i--) {
		if(a[i+1] > sum[i]*2) {printf("%lld\n",n-i); return 0;}
	}
	printf("%lld\n",n);
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int d,g;
    cin >> d >> g;
    int p[11],c[11];
    for(int i=0;i<d;i++)cin >> p[i] >> c[i];
    int ans=10000000;
    for(int mask=0;mask<(1<<d);mask++){
        int s=0,num=0,rest_max=-1;
        for(int i=0;i<d;i++){
            if(mask&1<<i){
                s+=100*(i+1)*p[i]+c[i];
                num +=p[i];
            }
            else{
                rest_max=i;
            }
        }
        if(s<g){
            int s1=100*(rest_max+1);
            int need = (g - s + s1 - 1) / s1;
            if(need > p[rest_max]){
                continue;
        }
        num+=need;
        }
        ans=min(ans,num);

    }
            cout << ans;
}

Measured memory_bytes: 256
alist = []
oplist = []
blist = []

while(1):
    a, op, b = map(str, input().split())

    if op == "?":
        break

    a = int(a)
    b = int(b)

    alist.append(a)
    oplist.append(op)
    blist.append(b)

for a, op, b in zip(alist, oplist, blist):
    if op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/":
        print(a // b)



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n; cin >> n;
  vector<int>x(n);
  int t=0;
  for(int i; i<n; i++){
    cin >> x[i]; t += x[i];
  }
  int m; cin >> m;
  vector<int>p(2);
  for(int i; i<m; i++){
    cin >> p[0] >> p[1];
    cout << t - x[p[0]-1] + p[1] << endl;
  }
}

Measured memory_bytes: 256
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
	let s = get_input();
    println!("{}", if s <= "2019/04/30".to_string() { "Heisei" } else { "TBD" } );
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n; ll k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());
    auto ok = [&](ll x) {
        ll cost = 0;
        for(int i = 0; i < n; i++) {
            cost += max(0LL, a[i] - x/f[i]);
        }
        return cost <= k;
    };
    ll l = -1, r = 1e18;
    while(r-l>1) {
        ll mid = (r+l)/2;
        if(ok(mid)) r = mid;
        else l = mid;
    }
    cout << r << endl;
}

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

using ll = long long int;
using P = pair<ll,ll>;
constexpr int INF = 1<<30;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> l(h, INF);
    vector<set<int> > st(h+1); 
    for(int i=0;i<n;i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        l[x] = min(l[x], y);
        st[x].insert(y);
    }
    int ans = h, ny = 0;
    for(int i=0;i<h;i++){
        if(l[i] < ny){
            ans = i;
            break;
        }
        if(st[i+1].count(ny+1) == 0) ny++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 19840
import java.util.*;	
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String o = sc.next();
		String e = sc.next();
		int a = 0,mozilong = o.length() + e.length();
		char ans[] = new char[mozilong];
		for(int i = 0;i < e.length() ;i++) {
			ans[a] = o.charAt(i);
			a++;
			ans[a] = e.charAt(i);
			a++;
		}
		if( o.length() > e.length())ans[a] = o.charAt(o.length()-1);
		System.out.println(ans);
	}

}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 100000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

char s[50][50];
int h, w;

int main()
{
    int n, m, k, i, j;
    int a, b, c, d;
    cin >> a >> b >> c >>d;
    
    const int lower = max(a,c);
    const int upper = min(b,d);

    cout << max(0, upper - lower) << endl;    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n;
    while (1) {
        cin >> n;
        if (!n)break;
        VI h(n + 1);
        cin >> h;
        FOR(i, 0, n + 1) {
            set<int> set;
            FOR(j, 0, n) {
                if (j == i)continue;
                if (j + 1 == i) {
                    if (i == n)continue;
                    set.insert(h[i + 1] - h[j]);
                }
                else set.insert(h[j + 1] - h[j]);
            }
            if (set.size() == 1) {
                cout << h[i] << "\n";
                break;
            }
        }
    }
}


Measured memory_bytes: 3112
n = int(input())
d = [list(map(int, input().split())) for i in range(n)]
for i in range(n - 2):
    if d[i][0] == d[i][1] and d[i + 1][0] == d[i + 1][1] and d[i + 2][0] == d[i + 2][1]:
        print("Yes")
        exit()
print("No")


Measured memory_bytes: 62408
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.Collections;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        int r = sc.nextInt();
        int c = sc.nextInt();
        int[][] ary = new int[r+1][c+1];
        
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++){
                ary[i][j] = sc.nextInt();
            }
        }
        
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                ary[i][c] += ary[i][j];
            }
        }

        for (int i = 0; i < c+1; i++) {
            for (int j = 0; j < r; j++) {
                ary[r][i] += ary[j][i];
            }
        }
        
        for (int i = 0; i < r+1; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < c+1; j++) {
                sb.append(ary[i][j]).append(" ");
            }
            sb.delete(sb.length()-1, sb.length());
            System.out.println(sb);
        }

    }
}

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

using namespace std;

int main(void)
{
    string s;
    cin >> s;
    int n = s.size();

    for(int i = 0; i < n - 1; i++)
    {
        if(s[i] == 'A' and s[i + 1] == 'C')
        {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
from heapq import heappop, heappush
X, Y, X, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q = []
heappush(Q,[-1*(A[0]+B[0]+C[0]),(0,0,0)])
memo = [(0,0,0)]
i,j,k = 0,0,0
for i in range(K):
  ans,(i,j,k) = heappop(Q)
  print(-ans)
  if (i+1,j,k) not in memo and i+1 < len(A):
    heappush(Q,[-1*(A[i+1]+B[j]+C[k]),(i+1,j,k)]) 
    memo.append((i+1,j,k))
  if (i,j+1,k) not in memo and j+1 < len(B):
    heappush(Q,[-1*(A[i]+B[j+1]+C[k]),(i,j+1,k)])
    memo.append((i,j+1,k))
  if (i,j,k+1) not in memo and k+1 < len(C):
    heappush(Q,[-1*(A[i]+B[j]+C[k+1]),(i,j,k+1)])
    memo.append((i,j,k+1))


Measured memory_bytes: 4848
#include <stdio.h>
#include <math.h>
#define PI 3.14159265359

int main(void)
{
    int a, b;
    double rad, S, L, h, c;
    
    scanf("%d %d %lf", &a, &b, &rad);
    
    rad = (rad / 180) * PI;
    c = sqrt (a * a + b * b - 2 * a * b * cos(rad));

    S = ((double)a * b * sin(rad)) / 2;
    L = a + b + c;
    h = b * sin(rad);
    
    printf("%.5f %.5f %.5f\n", S, L, h);
    
    return 0;
}

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

int main()
{
    int N; cin >> N;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
        if (a == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    ll ans = A[0];
    for (int i = 1; i < N; i++) {
        if (A[i] > (ll)1e18 / ans) {
            ans = -1;
            break;
        }
        ans *= A[i];
    }

    cout << ans << endl;
}


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

int main() {
    string s; cin >> s;
    int ans = 0;
    if(s == "SUN") ans = 7;
    if(s == "MON") ans = 6;
    if(s == "TUE") ans = 5;
    if(s == "WED") ans = 4;
    if(s == "THU") ans = 3;
    if(s == "FRI") ans = 2;
    if(s == "SAT") ans = 1;
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
typedef struct{
	int x,value;
}data;
data d[200];
int cd;
int comp(const void* a,const void* b){
	data* p=(data*)a;
	data* q=(data*)b;
	if(p->x==q->x){
		if(p->value<0)return 0;
		else if(q->value<0)return 1;
	}
	return p->x-q->x;
}
int main(){
	int n;
	int m,a,b;
	int i;
	while(1){
	scanf("%d",&n);
	if(n==0)return 0;
	cd=0;
	for(i=0;i<n;i++){
		scanf("%d %d %d",&m,&a,&b);
		d[cd].x=a;
		d[cd].value=m;
		cd++;
		d[cd].x=b;
		d[cd].value=-m;
		cd++;
	}
	qsort(d,2*n,sizeof(data),comp);
	int k=0;
	for(i=0;i<2*n;i++){
		k+=d[i].value;
		if(k>150)break;
	}
	if(i==2*n)printf("OK\n");
	else printf("NG\n");
	}
}
	

Measured memory_bytes: 1052
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	char a[105][105];
	int H,W,i;
	cin >> H >> W;
	for(i=0;i<H;i++)
	{
		cin >> a[i];
	}
	for(i=0;i<H;i++)
	{
		cout << a[i] <<endl;
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
#define all(v) v.begin(),v.end()
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    int h,w;
    cin >> h >> w;
    vector<vector<char>>maze(h,vector<char>(w));
    vector<vector<int>>cost(h,vector<int>(w,0));
    rep(i,h)rep(j,w)cin >> maze[i][j];
    rep(i,h){
        rep(j,w){
            if(i==0&&j==0) cost[i][j]=1;
            else if(maze[i][j]=='#'){
                cost[i][j]=0;
            }
            else if(maze[i][j]=='.'){
                if(i==0) cost[i][j]=cost[i][j-1];
                else if (j==0) cost[i][j]=cost[i-1][j];
                else {
                    cost[i][j]=cost[i-1][j]+cost[i][j-1];
                    cost[i][j]%=mod;
                }
            }
        }
    }
    cout << cost[h-1][w-1] <<endl;



    return 0;
}


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

int gcd2(int a, int b){
    int  g;
    for(int i= 1; i<=a; i++){
        if(a % i==0 && b % i==0){
            g=i;
        }
    }
    return g;
}
int main(){
  int a,b,k; cin>>a>>b>>k;
  if(k%gcd2(a,b)==0)cout<<"YES";
  else{cout<<"NO";}
}



Measured memory_bytes: 256
def count(st):
    n=len(st)
    tmp=1
    res=[]
    for i in range(n-1):
        if st[i]==st[i+1]:
            tmp+=1
        else:
            res.append(tmp)
            tmp=1
    res.append(tmp)
    return res
S=input()
K=int(input())
T=S*3
N=len(S)
if N==1:
    print(K//2)
    exit()
if K<=2:
    Y=count(S*K)
    ans=0
    for i in Y:
        ans+=i//2
    print(ans)
    exit()
if S.count(S[0])==N:
    print((N*K)//2)
    exit()
X=[]
if S[0]==S[-1]:
    for j in range(1,N):
        if S[j-1]!=S[j]:
            break
    tmp=1
    for i in range(j,j+N-1):
        if T[i]==T[i+1]:
            tmp+=1
        else:
            X.append(tmp)
            tmp=1
    X.append(tmp)
else:
    X=count(S)

cnt=0
for i in X:
    cnt+=i//2
Y=count(T)
cnt2=0
for i in Y:
    cnt2+=i//2
print(cnt*(K-3)+cnt2)


Measured memory_bytes: 38384
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string>

using namespace std;

int main()
{
    char N[17];
    if (scanf("%s", N) < 1) return 0;

    string s = N;
    int l = (int)s.length();

    bool flg = true;
    int sum = s[0] - '0';

    for (int i = 1; i < l; i++)
    {
        if (s[i] != '9') flg = false;
        sum += s[i] - '0';
    }

    if (flg)
    {
        printf("%d\n", sum);
    }
    else
    {
        int fst = s[0] - '1';
        printf("%d\n", fst + (l - 1) * 9);
    }

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <unordered_map>
#define ull unsigned long long
#define int long long
#define ll long long
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define mp(i, j) make_pair(i, j)
#define pb(x) push_back(x)
using namespace std;
// typedef vector<vector<ll>> matrix;
// const ll PRIME = 1e9 + 7;
// typedef pair<int,pair<int,int> >  ppi;

void solve()
{
   int l,r ,d;
   cin>>l>>r>>d;
   int ans=0;
   frf(i,l,r)
   {
       if(i%d==0)
       ans++;
   }
   cout<<ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t;
    // cin >> t
    t = 1;
    while (t--)
    {
        solve();
    }
}

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

using namespace std;

int main()
{
	string a, b; cin >> a >> b;
	string c = a + b;
	stringstream s(c);
	int x; 
	s >> x;
	if(floor(pow(x, 0.5)) == pow(x, 0.5))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc114/tasks/abc114_b

#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  string s;

  cin >> s;

  int n = INF;
  REP(i, s.length() - 2)
  {
    string t = s.substr(i, 3);
    int d = abs(753 - stoi(t));
    n = min(n, d);
  }

  cout << n << '\n';

  return 0;
}


Measured memory_bytes: 256
n = int(input())
_arr = list(map(int, input().split()))

ans = []
for first in (_arr[0], -1 * _arr[1] + 1, -1 * _arr[1] - 1, 1, -1):
    arr = _arr[:]
    c = 0
    prev = 0
    for i in range(n):
        t = prev + arr[i]
        if i == 0:
            c += abs(arr[i] - first)
            arr[i] = first
        elif prev > 0 and t >= 0:
            diff = t + 1
            c += diff
            arr[i] -= diff
        elif prev < 0 and t <= 0:
            diff = -1 * t + 1
            c += diff
            arr[i] += diff
        prev += arr[i]
    ans.append(c)
print(min(ans))

Measured memory_bytes: 63216
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    System.out.println(Math.max(Math.max(a+b,a-b),a*b));
  }
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  int n, k; cin >> n >> k;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
  }

  ll dp[n+1][k+1]; 

  rep(i, n+1) {
    rep(j, k+1) {
      dp[i][j] = 0;
    }
  }

  dp[0][0] = 1;

  rep(i, n) {
    ll sum = 0;
    for(int j=0; j<=k; 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;
      //cerr << i+1 << ' ' << j << ' ' << dp[i+1][j] << endl;
    }
  }
  cout << dp[n][k] << endl;
}

Measured memory_bytes: 79104
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> s;
typedef long long int ll;

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}

typedef pair<ll,ll> sl;
vector<sl> v;
int n,k;
vector<ll> x,y;
ll tmpx,tmpy;
ll area=0;
int main(){
  scanf("%d %d",&n,&k);
  REP(i,n){
    scanf("%lld %lld",&tmpx,&tmpy);
    x.push_back(tmpx);
    y.push_back(tmpy);
    v.push_back(sl(tmpx,tmpy));
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  sort(v.begin(),v.end());
  REP(i,n)for(int j=i+1;j<n;j++){
    REP(h,n)for(int l=h+1;l<n;l++){
      int cnt=0;
      for(int d=i;d<=j;d++){
        if(v[d].second>=y[h]&&v[d].second<=y[l]) cnt++;
      }
      if(cnt>=k&&(area==0||area > (y[l]-y[h])*(x[j]-x[i])) )
        area=(y[l]-y[h])*(x[j]-x[i]);
    }
  }
  printf("%lld\n", area);
  return 0;
}
/*
int main(){
  scanf("%d %d", &n,&k);
  REP(i,n){
    scanf("%lld %lld",&x,&y);
    v.push_back(sl(x,y));
  }
  sort(v.begin(),v.end());
  REP(i,k){
    vy.push_back(v[i].second);
  }
  sort(vy.begin(),vy.end());
  area = v[k-1].first*vy[k-1];
  for(int i=k;i<n;i++){
    vy.push_back(v[i].second);
    sort(vy.begin(),vy.end());
    if(area < v[i].first * vy[k-1]){
      area = v[i].first * vy[k-1];
    }
  }
  printf("%lld\n", area);
}
50c2*50c2
25*49*25*49
*/


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    Int n, k;
    cin >> n >> k;
    vector<Int> p(n);
    for (Int i = 0; i < n; i++) {
        cin >> p[i];
    }
    Int s[1001] = {};
    for (Int i = 0; i < 1000; i++) {
        s[i + 1] = s[i] + (i + 1);
    }
    vector<double> ss(n + 1, 0.0);
    for (Int i = 0; i < n; i++) {
        ss[i + 1] = (double)s[p[i]] / (double)p[i]; 
    }
    for (Int i = 0; i < n; i++) {
        ss[i + 1] += ss[i];
    }
    double res = 0.0;
    for (Int i = k; i <= n; i++) {
        res = max(res, ss[i] - ss[i - k]);
    }
    printf("%.12lf\n", res);
    return 0;
}


Measured memory_bytes: 3328
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        return a;
    }
    gcd(b, a % b)
}

fn main() {
    let n = read::<usize>();
    let v = read_vec::<i64>();
    let mut ans = v[0];
    for i in 1..n {
        ans = gcd(ans, v[i]);
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 8444
#include<bits/stdc++.h>
#define INF 1000000007
#define inf 10000000
#define mod 1000000007
using namespace std;
template <typename T> T Max(T X,T Y){return X>Y?X:Y;}
template <typename T> T Min(T X,T Y){return X<Y?X:Y;}
typedef long long ll;
int n,a[200005];
ll ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=2;i<=n;i++)
		if(a[i]<a[i-1])
		{
			ans+=ll(a[i-1]-a[i]);
			a[i]=a[i-1];
			
		}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4436
#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, t; cin >> N >> t;
    cout << max(0, N - t) << endl;
    

    return 0;
}


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

using namespace std;

#define INT_MAX (2*1e9)

int n;
int a[200005];
int flag[200005];
long long k;

int main()
{
    scanf("%d%lld", &n, &k);
    for(int i=0; i<=n; i++)
        flag[i] = ~flag[i];
    for(int i=1; i<=n; i++)
        scanf("%d", &a[i]);
    int times = 0;
    int loc = 1;
    flag[1] = 0;
    while(1){
        loc = a[loc];
        times++;
        if(flag[loc] != -1)
            break;
        flag[loc] = times;
    }
    if(k > flag[loc]){
        k -= flag[loc];
        k %= times-flag[loc];
    }
    else
        loc = 1;
    while(k--)
        loc = a[loc];
    printf("%d\n", loc);
}


Measured memory_bytes: 3296
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := map[string]int{}
	for i := 1; i <= n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		a[strconv.Itoa(tmp)] = i
	}

	for i := 1; i <= n; i++ {
		fmt.Print(a[strconv.Itoa(i)])
		fmt.Print(" ")
	}
	fmt.Println()
}


Measured memory_bytes: 12160
#include<stdio.h>
int main()
{
	int a,b,c;
	char op;
	do{
		scanf("%d %c %d",&a,&op,&b);
	
	if(op=='+')
	{
		c=a+b;
		printf("%d\n",c);
	}
	else if(op=='-')
	{
		c=a-b;
		printf("%d\n",c);
	}
	else if(op=='*')
	{
		c=a*b;
		printf("%d\n",c);
	}
	else if(op=='/')
	{
		c=a/b;
		printf("%d\n",c);
	}
	}while(op !='?');
	
	
}


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

int main(){
  string s;
  cin >> s ;
  int K=s.size();
  int L=s.size() ;
  for(int i=0;i<L-1 ;i++){
    if(s[i]!=s[i+1] ){
     int A=max(i+1,L-i-1);
     K=min(A,K);
      }
    }
  cout <<K<<endl;
  return 0;
  }


Measured memory_bytes: 512
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
using ll=long long;
const ll MOD=100000007;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}
inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return v[(size / 2) - 1] ;
}
template<class T> inline bool chmax(T& a,T b) {if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b) {if(a>b){a=b;return 1;} return 0;}

struct unionfind{
    vector<ll> d;
    unionfind(ll x):d(x,-1){}
    ll root(ll x) {return d[x]<0?x:d[x]=root(d[x]);}
    ll size(ll x) {return -d[root(x)];};
    bool unite(ll x,ll y) {x=root(x),y=root(y); if(x!=y){if(d[x]>d[y])swap(x,y);d[x]+=d[y];d[y]=x;}return x!=y;}
    bool find(ll x,ll y) {return root(x)==root(y);}
};

int main(){
  string s;
  cin>>s;
  ll k=s.size(),cnt=0;
  rep(i,0,k) if(s[i]=='x') cnt++;
  if(cnt<8)cout<<"YES";
  else cout<<"NO";
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#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 REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;



int dp[2020][2020];
int N, M;
int S[2020], T[2020];

int func(int i, int j) {
	if (dp[i][j] != 0) {
		//printf("%lld %lld: %lld\n", i, j, dp[i][j]);
		return dp[i][j];
	}
	if (S[i-1] != T[j-1]) {
		int res = func(i - 1,j) + func(i,j - 1) - func(i - 1,j - 1);
		if (res >= MOD)res -= MOD;
		else if (res < 0)res += MOD;
		dp[i][j] = res;
		//printf("%lld %lld: %lld\n", i, j, dp[i][j]);
		return dp[i][j];
	}
	else {
		int res = func(i - 1, j) + func(i, j - 1);
		if (res >= MOD)res -= MOD;
		dp[i][j]=res;
		
		//printf("%lld %lld: %lld\n", i, j, dp[i][j]);
		return dp[i][j];
	}
}
signed main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	cin >> N >> M;
	REP(i, N)cin >> S[i];
	REP(j, M)cin >> T[j];
	REP(i, N+1) {
		dp[i][0] = 1;
	}
	REP(j, M+1) {
		dp[0][j] = 1;
	}
	print(func(N, M));
}


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

#define ll long long
#define ull unsigned long long
#define ld long double
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
#define fo(i,start,end) for(int i=start;start<end?i<end:i>end;start<end?i+=1:i-=1)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vop vector<pll>
#define vov vector<vector<ll>>
#define endl "\n"
using namespace std;
const ld pi=3.14159265358979323;

const long long mod1=1e9+7;
const long long mod2=1e18;
const ll mod3=9e18;
const ll N=1e9+7;

long long power(ll  x, ll n){if(n==0)return 1;ll temp=power(x,n/2);if(n%2==0)return temp*temp;else return x*temp*temp;}

ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return (a*b)/(gcd(a,b));}
void swap(int* a, int* b){int t = *a;*a = *b;*b = t;}
bool f(ll x,ll y){return x>y;}

ll MAX(ll a,ll b){return a>b?a:b;}
ll MIN(ll x,ll  y){return x>y?y:x;}

ll pmod(ll a, ll b,ll mod)//a^b%mod
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b/=2;
        a=(a*a)%mod;
    }
    return ans;
}

bool cmp2( pair<ll,ll> &a,
           pair<ll,ll> &b)
{
    return a.second>b.second;
}


void solve() {
    ll n;ll k;
    cin>>n>>k;
    ll arr[n+1];
    fo(i,1,n+1)cin>>arr[i];
    ll ans[n+1];
    ans[0]=ans[1]=0;
    ans[2]=abs(arr[2]-arr[1]);
    for(ll i=3;i<n+1;i++){
        ans[i]=mod3;
        for(ll j=1;j<=min(k,i-1);j++){
            ans[i]=MIN(ans[i],ans[i-j]+abs(arr[i]-arr[i-j]));

        }





    }

    cout<<ans[n];




}

























int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin) ;
    freopen("output.txt" , "w" , stdout) ;
    //freopen("error.txt" , "w" , stderr) ;
#endif








    ll t;
    t=1;
    //  cin>>t;
    //  cin.ignore();
    while(t--){

        solve();
    }




    return 0;


}

////vll adj[100001];
////ll vis[100001];
////ll sssp[100001];

Measured memory_bytes: 5216
/**
*   @author: Kshitiz Srivastava (Pirate_ksh) @ MNNIT Allahabad
*/
#include<bits/stdc++.h>
using namespace std;
 
// General
#define ll long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define mod9 998244353 
#define endl "\n"
#define debug(x) cout<<x<<endl
#define REP(i,n) for(i=0;i<n;++i)
#define FOR(i,x,n) for(i=x;i<n;++i)
 
// Bounds
#define lb(a, x) a.lower_bound(x)
#define ub(a, x) a.upper_bound(x)
#define all(a) a.begin(),a.end()
 
// Vector
#define vi vector <int>
#define pb(v, x) v.push_back(x)
#define vsi vector <set <int> >
 
// Map
#define mii map <int, int>
 
// Set
#define si set <int>
 
// Pair
#define vpii vector<pair < int, int > >
#define pii pair < int, int >
#define F first
#define S second


ll w[100] = {0}, v[100] = {0};
ll dp[101][100001];
ll KnapSack(ll W, ll n) {
    if(W <= 0 || n == 0) return 0;
    if(dp[n][W] == -1) {
        if(w[n-1] > W) dp[n][W] = KnapSack(W, n-1);
        else
            dp[n][W] = max(v[n-1] + KnapSack(W-w[n-1], n-1), KnapSack(W, n-1));
    }
    return dp[n][W];
}

int main(){
    io;
    ll t, n, i, j;
    t=1;
    // cin >> t;
    ll W, k;
    while(t--) {
        cin >> n >> W;
        REP(i, n) cin >> w[i] >> v[i];
        memset(dp, -1, sizeof(dp));
        cout << KnapSack(W, n) << endl;   
    }   
    return 0;
}

Measured memory_bytes: 79232
#include<bits/stdc++.h>
#define fi        first
#define se        second
#define PI        acos(-1)
#define LC(a)     ((a<<1))
#define RC(a)     ((a<<1)+1)
#define MID(a,b)  ((a+b)>>1)
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS()     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<ll,ll>   PLL;
typedef pair<ll,int>  PLI;
const int INF = 0X3F3F3F3F;
const int MIN = -(1<<30);
const ll N = 1e5+7;
int main()
{
	IOS();
	
	int n;
	string s;
	cin>>n>>s;
	int ans=0;
	for(int i=0;i<=s.size()-3;i++)
	{
		string a = s.substr(i,3);
	//	cout<<a<<endl;
		if(a=="ABC") ans++;
	}
	
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e5+5;
const int mod=1e9+7;
ll y,k;
set<ll> st = {1, 2, 3, 4, 5, 6, 7, 8, 9};

void solve() {
    priority_queue<ll, vector<ll>, greater<ll>> q;
    for (auto &x : st) q.emplace(x);
    while (!q.empty()) {
        if (st.size() >= 1e5) return;
        auto x = q.top();
        q.pop();
        y = x * 10 + x % 10;
        if (abs(y % 10 - x % 10) <= 1) {
            if (!st.count(y)) {
                st.insert(y);
                q.push(y);
            }
        }
        y--;
        if (abs(y % 10 - x % 10) <= 1) {
            if (!st.count(y)) {
                st.insert(y);
                q.push(y);
            }
        }
        y+=2;
        if (abs(y % 10 - x % 10) <= 1) {
            if (!st.count(y)) {
                st.insert(y);
                q.push(y);
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    cin >> k;
    vector<ll> v;
    for (auto &x : st) v.emplace_back(x);
    cout << v[k - 1] << endl;
    return 0;
}


Measured memory_bytes: 6768
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input1 = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var H = input1[0];
        var N = input1[1];
        var input2 = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        var win = H <= input2.Sum();
        var result = win ? "Yes" : "No";

        Console.WriteLine(result);
    }
}

Measured memory_bytes: 20192
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int main(){
  int i;
  int A = 0;
  for(i=(0);i<(3);i++){
    A += rd_int();
  }
  if(A>21){
    wt_L("bust");
    wt_L('\n');
  }
  else{
    wt_L("win");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191214-1

// --- original code ---
// {
//   int A = 0;
//   rep(i,3) A += rd_int();
//   wt(if[A>21,"bust","win"]);
// }


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

int to[200001], ne[200001], he[100001], saidai, saidaiv;
void dfs1(int v, int mae, int d) {
	if (saidai < d) {
		saidai = d;
		saidaiv = v;
	}
	for (int i = he[v]; i; i = ne[i]) {
		if (to[i] != mae) dfs1(to[i], v, d + 1);
	}
}

vector<int> kazu;
bool dfs2(int v, int mae) {
	bool ret = (saidaiv == v);
	int cnt = 0;
	for (int i = he[v]; i; i = ne[i]) {
		if (to[i] != mae) {
			ret |= dfs2(to[i], v);
			cnt++;
		}
	}
	if (ret) kazu.pb(cnt);
	return ret;
}

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


	int N = getint();
	int k = 1;
	rep(i, N - 1) {
		int u = getint(), v = getint();
		to[k] = v;
		ne[k] = he[u];
		he[u] = k++;
		to[k] = u;
		ne[k] = he[v];
		he[v] = k++;
	}

	dfs1(1, 0, 0);
	int tmp = saidaiv;
	saidai = 0;
	dfs1(tmp, 0, 0);

	dfs2(tmp, 0);

	int s = kazu.size() / 2 - 1;
	int n = kazu.size();

	bool gyaku = 0;
	rep1(i, s) {
		if (kazu[i] > kazu[n - i - 1]) {
			gyaku = 1;
			break;
		}
		else if (kazu[i] < kazu[n - i - 1]) {
			break;
		}
	}

	k = 2;
	putint(1);
	if (gyaku) {
		for (int i = n - 2; i >= 1; i--) {
			rep1(j, kazu[i] - 1) putint(k + j);
			putint(k);
			k += kazu[i];
		}
	}
	else {
		rep1(i, n - 2) {
			rep1(j, kazu[i] - 1) putint(k + j);
			putint(k);
			k += kazu[i];
		}
	}
	putint(N);

	if (k != N) {
		printf("-1");
	}
	else {
		fwrite(dn, 1, di - dn, stdout);
	}

	Would you please return 0;
}

Measured memory_bytes: 6264