akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<15;
const ll MOD = 1e9+7;
const double EPS = 1e-9;

void update(vector<vector<int>> dist, int h, int w){
  queue<tuple<int, int, int>> que;
  
}

int main(int argc, const char * argv[]) {
  int H, W; cin >> H >> W;
  vector<vector<char>> stage(H, vector<char>(W));
  vector<vector<int>> dist(H, vector<int>(W, INF));
  set<pair<int,int>> newblack, nextblack;
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++){
      cin >> stage[i][j];
      if (stage[i][j] == '#') {
        dist[i][j] = 0;
        newblack.insert(make_pair(i,j));
      }
    }
  }
  vector<int> dh{1,-1,0,0}, dw{0,0,1,-1};
  int ans = 0;
  int blacknum = (int)newblack.size();
  int h, w, nh, nw;
  while(blacknum != H*W){
    for (auto p: newblack){
      h = p.first; w = p.second;
      for (int i=0; i<4; i++){
        nh = h+dh[i]; nw = w+dw[i];
        if (nh<H && nh>=0 && nw<W && nw>=0){
          if (dist[nh][nw] == INF){
            dist[nh][nw] = ans+1;
            nextblack.insert(make_pair(nh, nw));
          }
        }
      }
    }
    newblack = nextblack;
    nextblack.clear();
    blacknum += (int)newblack.size();
    ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 52864
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    n, m = map(int, input().split())

    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(int, input().split())
        uf.union(a - 1, b - 1)

    print(uf.group_count() - 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 74488
// header {{{
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <stack>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;

#define kita            cout << "kita\n"
#define print2(i, n)    cout << (i) << ": " << (n) << endl
#define print3(i, j, n)     cout << "(" << (i) << ", " << (j) << ") : " << (n) << endl
#define print4(i, j, n, m)  cout << "(" << (i) << ", " << (j) << ") : " << (n) << ", " << (m) << endl
#define print_mat(mat, h, w) for(int i=0;i<(h);i++){for(int j=0;j<(w);j++){cout << mat[i][j] << " ";}cout << endl;}

#define EPS (1e-10)
#define EQ(a, b) (fabs((a)-(b)) < eps)

typedef long long ll;
typedef unsigned long long ull;
// }}}

#define SIZE      100005
#define MOD 1000000007LL

ll pow(ll a, ll b) {
    if(b == 0) return 1;
    ll aa = pow(a, b/2);
    return aa*aa%MOD*(b%2 == 1 ? a : 1)%MOD;
}

ll fact[SIZE] = {1, 1};
ll finv[SIZE] = {1, 1};

void fact_init() {
    // fact
    for(ll i=2;i<SIZE;i++){
        fact[i] = fact[i-1]*i%MOD;
    }

    // finv
    finv[SIZE-1] = pow(fact[SIZE-1], MOD-2);
    for(ll i=SIZE-1;i>=3;i--){
        finv[i-1] = finv[i]*i%MOD;
    }
}

ll comb(int n, int r) {
    if(r > n) return 0;
    return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD;
}

ll gcd(ll x, ll y) {
    return y ? gcd(y, x%y) : x;
}


int main() {
    fact_init();
    int n, m;
    cin >> n >> m;

    if(n == m){
        cout << fact[n]*fact[m]%MOD*2%MOD << endl;
    }else if(abs(n-m) == 1){
        cout << fact[n]*fact[m]%MOD << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}


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

struct UnionFind {
  vector<int> d;

  UnionFind(int n = 0) : d(n, -1) {}

  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }

  void unite(int x, int y) {
    int rx = find(x);
    int ry = find(y);
    if (rx == ry) return;
    if (ry < rx) swap(rx, ry);
    d[rx] += d[ry];
    d[ry] = rx;
  }

  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;

  UnionFind uf(n);

  vector<int> f(n, 0);
  rep(i, m) {
    int a, b;
    cin >> a >> b;

    a--;
    b--;

    f[a]++;
    f[b]++;

    uf.unite(a, b);
  }

  vector<int> g(n, 0);
  rep(i, n) g[i] = uf.size(i) - f[i] - 1;

  rep(i, k) {
    int c, d;
    cin >> c >> d;

    c--;
    d--;

    if (uf.same(c, d)) {
      g[c]--;
      g[d]--;
    }
  }

  string s;
  rep(i, n) {
    s += to_string(g[i]);

    if (i != n-1) {
      s += " ";
    }
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 5448
C = [list(map(int, input().split())) for i in range(3)]

for a1 in range(-100, 101):
  b = [c - a1 for c in C[0]]
  for a2 in range(-100, 101):
    if b != [c - a2 for c in C[1]]:
      continue
    for a3 in range(-100, 101):
      if b == [c - a3 for c in C[2]]:
        print('Yes')
        quit()

print('No')

Measured memory_bytes: 3064
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

int main()
{
	int x = 0;
	cin >> x;
	if (x < 1200)
	{
		cout << "ABC";
	}
	else if (x < 2800)
	{
		cout << "ARC";
	}
	else
	{
		cout << "AGC";
	}
	return 0;
}

Measured memory_bytes: 256
# encoding: utf-8
N = int(input())
s = [int(input()) for i in range(N)]

s.sort()
ans = sum(s)
if ans % 10 > 0:
    print(ans)
else:
    for si in s:
        if si % 10 > 0: break
    else:
        ans = si # 0            
    print(ans - si)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r){
  if(l >= r) return;
  int root = pre[pos++];
  int m = distance(in.begin(), find(in.begin(), in.end(), root));
  rec(l, m);
  rec(m+1, r);
  post.push_back(root);
}

void solve(){
  pos = 0;
  rec(0, pre.size());
  rep(i, n){
    if(i) cout << " ";
    cout << post[i];
  }
  cout << endl;
}

int main(){
  cin >> n;
  rep(i, n){
    int a; cin >> a;
    pre.push_back(a);
  }
  rep(i, n){
    int a; cin >> a;
    in.push_back(a);
  }

  solve();

  return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x) {cout << #x << " = " << (x) << endl;}

LL solve(LL v, VVI& G, VI& dp) {
    if (dp[v] != -1) return dp[v];
    LL length = 0;
    EACH(w, G[v]) {
        length = max(length, solve(w, G, dp) + 1);
    }
    return dp[v] = length;
}

int main() {
    LL N, M;
    cin >> N >> M;
    VVI G(N + 1);
    REP(i, M) {
        LL x, y;
        cin >> x >> y;
        G[x].PB(y);
    }

    VI dp(N + 1, -1);
    FOR(i, 1, N + 1) {
        solve(i, G, dp);
    }

    cout << *max_element(ALL(dp)) << endl;
	
    return 0;
}


Measured memory_bytes: 9216
from itertools import accumulate

N = int(input())
A1 = [int(i) for i in input().split()]
A2 = [int(i) for i in input().split()]
A2.reverse()
A1_cumsum = list(accumulate(A1))
A2_cumsum = list(accumulate(A2))
ans = 0
for u, d in zip(A1_cumsum, A2_cumsum[::-1]):
    ans = max(ans, u+d)
print(ans)


Measured memory_bytes: 38256
from collections import Counter
def counter(li, n):
    count = Counter()
    count.update(li)
    return count[n]


import sys
input = sys.stdin.readline
N, M = map(int, input().split())
li_food = [0]*M
for i in range(N):
    li_input = list(map(int, input().split()))
    li_input = li_input[1:]
    for j in li_input:
        li_food[j-1] += 1
print(counter(li_food, N))

Measured memory_bytes: 38384
N, M = map(int, input().split())

MOD = 10**9 + 7

ans = 1
if abs(N-M) >= 2:
    print(0)
else:
    for i in range(1, N+1):
        ans = ans * i % MOD

    for i in range(1, M+1):
        ans = ans * i % MOD
    if N == M:
        print(ans*2%MOD)
    else:
        print(ans)


Measured memory_bytes: 9068
#include<stdio.h>
int table[9][9];
bool NG[9][9];
int main(){
	int a;
	scanf("%d",&a);
	while(a--){
		for(int i=0;i<9;i++)
			for(int j=0;j<9;j++)
				scanf("%d",&table[i][j]);
		for(int i=0;i<9;i++)
			for(int j=0;j<9;j++)
				NG[i][j]=false;
		for(int i=0;i<9;i++){
			for(int j=0;j<9;j++){
				bool ok=true;
				for(int k=0;k<9;k++){
					if(table[i][j]==table[i][k]&&j!=k)ok=false;
				}
				for(int k=0;k<9;k++){
					if(table[i][j]==table[k][j]&&i!=k)ok=false;
				}
				int seci=i/3;
				int secj=j/3;
				for(int k=0;k<3;k++){
					for(int l=0;l<3;l++){
						if(table[seci*3+k][secj*3+l]==table[i][j]&&seci*3+k!=i&&secj*3+l!=j)ok=false;
					}
				}
				if(!ok)NG[i][j]=true;
			}
		}
		for(int i=0;i<9;i++){
			for(int j=0;j<9;j++){
				printf(NG[i][j]?"*":" ");
				printf("%d",table[i][j]);
			}
			printf("\n");
		}
		if(a)printf("\n");
	}
}

Measured memory_bytes: 0
//cwystc <--> 陈威宇是天才  --by cwy
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const double PI=acos(-1);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for (int i=(a);i<=(b);i++)
#define per(i,a,b) for (int i=(a);i>=(b);i--)
#define Rep(i,a,b) for (int i=(a);i<(b);i++)
#define Per(i,a,b) for (int i=(a);i>(b);i--)
#define travel_set(it,a) for (set<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_map(it,a) for (map<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define travel_vec(it,a) for (vector<int>::iterator (it)=(a).begin();(it)!=(a).end();(it)++)
#define p(x) cout << x << endl;
#define def cout << "find" << endl;
#define what_is(x) cout << #x << " is " << x << endl;
template <class T>T sqr(T x){return x*x;}
template <class T>T alex(T x){return (x>0)?x:-x;}
template <class T>void read(T&x){
	x=0;T f=1;char ch=getchar();
	while ((ch<48||ch>57)&&ch!=45)ch=getchar();
	if (ch==45)f=-1,ch=getchar();
	while (ch>=48&&ch<=57)x=x*10+ch-48,ch=getchar();
	x*=f;
}

//-------------------------------------------------head-------------------------------------------------

#define maxn 500005
#define mod 998244353
int fac[maxn],inv[maxn];
int n,k;
int power(int a,int b,int p){
	int s=1,w=a;
	while (b){
		if (b&1)s=(ll)s*w%p;
		w=(ll)w*w%p;b>>=1;
	}
	return s;
}
int C(int x,int y){
	if (y>x)return 0;
	return (ll)fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main(){
	fac[0]=1;Rep(i,1,maxn)fac[i]=(ll)fac[i-1]*i%mod;
	Rep(i,0,maxn)inv[i]=power(fac[i],mod-2,mod);
	read(n);read(k);int res=0;
	rep(R,max((k+1)/2,n),k){
		int B=k-R,T=max(min(R-B,R-n),0);
		if (B==R)res=((res+C(R+B-1,R))%mod+mod-C(R+B-1,k-n+1))%mod;else
		res=((res+C(R+B,R))%mod+mod-C(R+B,R+R-n+1))%mod;
	}
	printf("%d\n",res);return 0;
}

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

ll gcd(ll a, ll b){
  if(b==0)return a;
  return gcd(b, a%b);
}

int main(){
  ll a, b, c, ans=2;
  cin>>a >>b;
  c = gcd(a, b);
  
  for(ll i=2;i<=sqrt(c);i++){
    if(c%i==0){
      while(c%i==0)c/=i;
      ans++;
    }
  }
  if(c==1)ans--;
  cout<<ans<<endl;
  return 0;
}

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

struct State{
	int lx, ly, rx, ry;
	State(int lx_, int ly_, int rx_, int ry_){
		lx = lx_; ly = ly_; rx = rx_; ry = ry_;
	}
};

const int INF = 1e+8;
bool stamp[4][4][4][4] = {0};
vector<State> v;
char C[5][5];
int d[1<<16];
char color[3] = {'R','G','B'};


void init(){
	for(int ly=0 ; ly < 4 ; ly++ ){
		for(int lx=0 ; lx < 4 ; lx++ ){
			for(int ry=0 ; ry < 4 ; ry++ ){
				for(int rx=0 ; rx < 4 ; rx++ ){
					stamp[ly][lx][ry][rx] = false;
				}
			}
		}
	}
}

void check_stamp(int w, int h){
	for(int dy = -3 ; dy <= 3 ; dy++ ){
		for(int dx = -3 ; dx <= 3 ; dx++ ){
			int lx=4, ly=4, rx=-1, ry=-1;
			for(int y = dy ; y < dy + h ; y++ ){
				for(int x = dx ; x < dx + w ; x++ ){
					if( x < 0 || y < 0 || 4 <= x || 4 <= y ) continue;
					lx = min(lx, x);
					ly = min(ly, y);
					rx = max(rx, x);
					ry = max(ry, y);
				}
			}
			
			if( lx < 0 || 4 <= lx || ly < 0 || 4 <= ly ) continue;
			if( rx < 0 || 4 <= rx || ry < 0 || 4 <= ry ) continue;
			stamp[ly][lx][ry][rx] = true;
		}
	}
}

int solve(){
	for(int i=0 ; i < (1<<16) ; i++ ){
		d[i] = INF;
	}
	d[0] = 0;
	queue<int> q;
	q.push( 0 );
	
	int res = INF;
	while( !q.empty() ){
		int bits = q.front();
		int cost = d[bits];
		q.pop();
		
		if( bits == (1<<16)-1 ){
			res = cost;
			break;
		}
		for(int i=0 ; i < v.size() ; i++ ){
			for(int j=0 ; j < 3 ; j++ ){
				int next = bits;
				for(int y=0 ; y < 4 ; y++ ){
					for(int x=0 ; x < 4 ; x++ ){
						if( v[i].ly <= y && y <= v[i].ry && v[i].lx <= x && x <= v[i].rx ){
							if( next & (1<<(y*4+x)) ){ // テヲツュツ」テ」ツ?療」ツ??」ツ?ィテ」ツ?禿」ツつ催」ツ?ォティツ可イjテ」ツつ津・ツ。ツ療」ツつ?
								if( color[j] != C[y][x] ){ // 1 => 0
									next = next & ~(1<<(y*4+x));
								}
							}else{ // テヲツュツ」テ」ツ?療」ツ?湘・ツ。ツ療」ツつ古」ツ?ヲテ」ツ??」ツ?ェテ」ツ??」ツ?ィテ」ツ?禿」ツつ催」ツ?ォテ・ツ。ツ療」ツつ?
								if( color[j] == C[y][x] ){ // 0 => 1
									next = next | (1<<(y*4+x));
								}
							}
						}
					}
				}
				if( d[next] == INF ){
					d[next] = cost + 1;
					q.push(next);
				}
			}
		}
	}
	return res;
}

void make_stamp(){
	// テ」ツつケテ」ツつソテ」ツδウテ」ツδ療」ツ?ョテ・ツ。ツ療」ツつ甘ヲツ鳴ケテ」ツ?ョテ」ツδ?」ツつァテ」ツδε」ツつッ (テ・ツ、ツ堙」ツ?湘」ツ?ヲテ」ツつ?00テゥツ?堙」ツつ?
	for(int ly=0 ; ly < 4 ; ly++ ){
		for(int lx=0 ; lx < 4 ; lx++ ){
			for(int ry = ly ; ry < 4 ; ry++ ){
				for(int rx = lx ; rx < 4 ; rx++ ){
					if( stamp[ly][lx][ry][rx] ){
						if( lx < 0 || 4 <= lx || ly < 0 || 4 <= ly ) continue;
						if( rx < 0 || 4 <= rx || ry < 0 || 4 <= ry ) continue;
						v.push_back( State(lx,ly,rx,ry) );
					}
				}
			}
		}
	}
}

int main(){
	init();
	
	int N;
	cin >> N;
	for(int i=0 ; i < N ; i++ ){
		int h, w;
		cin >> h >> w;
		check_stamp(w, h);
	}
	for(int y=0 ; y < 4 ; y++ ){
		cin >> C[y];
	}
	make_stamp();
	
	int ans = solve();
	cout << ans << endl;
}

Measured memory_bytes: 1612
import numpy as np
N,K=map(int, input().split())
A =list(map(int,input().split()))
MOD = 10 ** 9 + 7
if N==K:
  ans0 = 1
  for a in A[0:N]:
    ans0 *= a
    ans0 %= MOD
  print(ans0)
  exit()
A=sorted(A)  
if (K%2==1 and A[-1]<0):
  ans1 = 1
  for a in A[N-K:N]:
    ans1 *= a
    ans1 %= MOD
  print(ans1)
  exit()
 
A=sorted(A, key=lambda x:abs(x), reverse=True)
AA=[np.sign(i) for i in A]
 
ansA = 1
for a in A[0:K]:
  ansA *= a
  ansA %= MOD
ansAA = AA[0:K].count(-1)%2
if ansA==0 or ansAA==0:
  print(ansA)
  exit()

while ansA>0:
  ansA-=MOD

B1=A[0:K]
C1=A[0:K]
B2=sorted(A[K:N])
Bp=[i for i in A[0:K] if i>0]
Bm=[i for i in A[0:K] if i<0]
 
if B2[0]>0:B2.insert(0,0)
if B2[-1]<0:B2.insert(-1,0)
if not Bp:Bp.insert(0,B1[-1])
if not Bm:Bm.insert(0,B1[0])
  
#print(Bp,Bm,B2)
#print(Bp[-1],B2[0])
B1.remove(Bp[-1])
B1.append(min(B2[0],0))
#print(B1)
ansB = 1
for a in B1[0:K]:
  ansB *= a
  ansB %= MOD
#print(Bm[-1],B2[-1])
C1.remove(Bm[-1])
C1.append(max(B2[-1],0))
 
ansC = 1
for a in C1[0:K]:
  ansC *= a
  ansC %= MOD
#print(B1,C1)
#print(ansB,ansC)
BB1=[np.sign(i) for i in B1]
ansBB1 = BB1[0:K].count(-1)%2
BB2=[np.sign(i) for i in C1]
ansBB2 = BB2[0:K].count(-1)%2
#print(ansBB1,ansBB2)
if ansBB1==1:
  print(ansC)
  exit()
if ansBB2==1:
  print(ansB)
  exit()
#print(B2[0]/Bp[-1],B2[-1]/Bm[-1])
#print(Bp[-1]*B2[-1],Bm[0]*B2[0])

#print(abs(Bp[-1]*B2[-1])-abs(Bm[-1]*B2[0]))
#print(ansB,ansC)
if abs(Bp[-1]*B2[-1])-abs(Bm[-1]*B2[0])>=0:
  print(ansC)
else: print(ansB)

Measured memory_bytes: 65648
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long k = sc.nextLong();
		long result = 0;
		if(k >= a){
			result += a;
			if(k > a + b){
				result -= k - a - b;
			}
		}else{
			result += k;
		}
		System.out.println(result);
	}
}


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

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main() {
  int N{0};
  int AC{0}, WA{0}, TLE{0}, RE{0};

  cin >> N;
  std::vector<string> S(N);

  for (auto &s : S) {
    cin >> s;
    if ( s == "AC" ) AC++;
    if ( s == "WA" ) WA++;
    if ( s == "TLE" ) TLE++;
    if ( s == "RE" ) RE++;
  }

  cout << "AC x " << AC << "\n";
  cout << "WA x " << WA << "\n";
  cout << "TLE x " << TLE << "\n";
  cout << "RE x " << RE << "\n";
}


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

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 998244353

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll n;
    cin >> n;
    vi arr(n), dp(n, 0);
    REP(i, 0, n)
        cin >> arr[i];
    dp[n-1] = 0;
    dp[n-2] = abs(arr[n-2] - arr[n-1]);
    RREP(i, n-3, -1)
        dp[i] = min(dp[i+1] + abs(arr[i] - arr[i+1]), dp[i+2] + abs(arr[i] - arr[i+2]));
    cout << dp[0] << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.nextString();
            out.println(s.substring(0, s.length() - 8));
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



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

struct point{
	int x;
	int y;
	int d;
	point (int a,int b,int c){
		x=a;
		y=b;
		d=c;
	}
};

queue <point> q;
int n,m,a[55][55],s,mo[4][2]={1,0,0,1,-1,0,0,-1};
bool v[55][55];

int main(){
	char ch;
	int i,j;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++){
		for (j=1;j<=m;j++){
			cin>>ch;
			if (ch=='.'){
				s++;
				a[i][j]=0;
			}
			else{
				a[i][j]=1;
			}
		}
	}
	point p(1,1,1);
	q.push(p);
	v[1][1]=true;
	while (!q.empty()){
		int X=q.front().x,Y=q.front().y,D=q.front().d,xx,yy;
		for (i=0;i<4;i++){
			xx=X+mo[i][0];
			yy=Y+mo[i][1];
			if (xx>=1 && xx<=n && yy>=1 && yy<=m){
				if (!v[xx][yy] && a[xx][yy]==0){
					point np(xx,yy,D+1);
					q.push(np);
					v[xx][yy]=true;
					if (xx==n && yy==m){
						printf("%d",s-D-1);
						return 0;
					}
				}
			}
		}
		q.pop();
	}
	printf("-1");
	return 0;
}

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

ifstream fin("pentagon.in");
ofstream fout("pentagon.out");

#define NMAX 2005
#define INF -1000000


int main()
{

   unsigned long long n;
   unsigned long long c = 0;
   cin>>n;

   c = (n / 500 ) * 1000 + (n%500) / 5 * 5;
   cout<<c;

   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
using namespace std;
int map[10000][10000];

int main(){
  int n;
  string s;
  pair<int, int> point;
  cin>>n;
  cin>>s;
  map[0][0]=0;
  int max=0;
  for(int i=1;i<n;i++){
    if(s[i]==s[0]){
      map[i][0]=1;
      map[0][i]=1;
    }
    else {
      map[0][i]=0;
      map[i][0]=0;
    }
  }
  for(int i=1;i<n;i++){
    for(int j=1;j<n;j++){
      map[i][j]=0;
      if(s[i]==s[j]){
	map[i][j]=map[i-1][j-1]+1;
    }
      int length=i-j;
      if(length<0) length=length*(-1);
      if(i==j) map[i][j]=0;
      if(max<map[i][j])
	if(map[i][j]<=length){
	max=map[i][j];
	point.first=i;
	point.second=j;
      }
    }
  }
  cout<<max<<endl;
  return 0;
}


Measured memory_bytes: 196096
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define DR(i,a,b) for (int i=(b); i-->(a);)
#define D(i,n) DR(i,0,n)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,v)
#define MA(a,v) a = max(a,v)
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream &operator<<(ostream &os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i];
    return os;
}
const bool debug = 1;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin>>n;
    cout<<180*(n-2)<<"\n";
}

Measured memory_bytes: 256
import itertools

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

if n == 1:
    if a == b:
        print(1)
    else:
        print(0)
elif n == 2:
    print(1)
elif n >= 3:
    if a > b:
        print(0)
    else:
        smin = a * n + (b-a)
        smax = b * n - (b-a)
        print(smax-smin+1)

Measured memory_bytes: 3060
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const int MINF = -1e9;;


int main() {
	int n;
	cin >> n;
	cout << (n + 1) / 2 -1<< endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

    long long K, A, B;
    cin >> K >> A >> B;

    long long ans;
    if (A + 2 >= B){
        ans = 1 + K;
    }else{
        K = K - (A - 1);

        if (K % 2 == 0){
            ans = A + (B - A) * (K / 2);
        }else{
            K = K - 1;
            ans = A + 1 + (B - A) * (K / 2);
        }
    }
    
    cout << ans << endl;

    return 0;
}

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

using namespace std;

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

    int h, n;
    cin >> h >> n;

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

    vector<int> dp(h+1, numeric_limits<int>::max());
    dp[0] = 0;
    for(int k=0; k<=h; k++){
        for(int j=0; j<n; j++){
            int target = max(k - a[j], 0);
            dp[k] = min(dp[k], dp[target] + b[j]);
        }
    }

    cout << dp[h] << "\n";
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	vector<pair<long long, long long>> point(n);
	for(int i = 0; i < n; i++) cin >> point[i].first >> point[i].second;
	sort(point.begin(), point.end());
	long long prefix_mx_below = - (point[0].first + point[0].second);
	long long prefix_mx_above = - point[0].first + point[0].second;
	long long res = LONG_LONG_MIN;
	for(int i = 1; i < n; i++){
		res = max({res, prefix_mx_below+point[i].first+point[i].second, 
						prefix_mx_above+point[i].first-point[i].second});
		prefix_mx_below = max(prefix_mx_below, - point[i].first - point[i].second);
		prefix_mx_above = max(prefix_mx_above, - point[i].first + point[i].second);
	}
	cout << res << '\n';
	return 0;
}



Measured memory_bytes: 6348
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int cnt(int x){
    int res = 0;
    while(x%2 == 0){
        x /= 2;
        ++res;
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    int mx = 0;
    int ans = 1;
    for(int i=1;i<=n;i++){
        int mm = cnt(i);
        if(mm > mx){
            mx = mm;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

  vector<string> s(N);
  for (int i = 0; i < N; i++)
  {
    cin >> s.at(i);
  }

  int M;
  cin >> M;
  vector<string> t(M);
  for (int i = 0; i < M; i++)
  {
    cin >> t.at(i);
  }

  int count = 0;
  for (string i : s)
  {
    int count_tmp = 0;
    for (string j : s)
    {
      if (i == j)
        count_tmp++;
    }

    for (string j : t)
    {
      if (i == j)
      {
        count_tmp--;
      }
    }

    if (count < count_tmp)
      count = count_tmp;
  }

  cout << count << endl;
}


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

using namespace std;

#define bug(x) cerr << #x << " = " << x << '\n'
#define ll     long long
#define maxn

int main() {
        //freopen(".inp","r",stdin);

        string s;
        cin >> s;

        int o = 0, ret = 0;
        for(int i = 0; s[i]; ++ i) {
            if(s[i] == 'R') o ++;
            else o = 0;
            ret = max(ret, o);
        }
        cout << ret;
}



Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 30);
const double PI = acos(-1);

typedef pair<char,char> P;

int N;

bool indCheck(int ind) {
	if (ind < 0 || ind >= N)return false;
	return true;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	vi A(N);
	REP(i, N)cin >> A[i];
	int ind = 0;
	int ans = 0;
	while (indCheck(ind)) {
		int isPlus = 0; // 0=>未確定 1=>単調非減少 2=>単調非増加
		ans++;
		int pre = A[ind];
		ind++;
		while (indCheck(ind)) {
			bool b = true;
			switch (isPlus) {
				case 0:
					if (A[ind] > pre) {
						isPlus = 1; pre = A[ind];
					}
					else if (A[ind] < pre) {
						isPlus = 2; pre = A[ind];
					}
					break;
				case 1:
					if (A[ind] < pre)b = false;
					else pre = A[ind];
					break;
				case 2:
					if (A[ind] > pre)b = false;
					else pre = A[ind];
					break;
			}
			if (!b)break;
			ind++;
		}
	}
	cout << ans << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 888
fact = [1]
for i in range(20):
    fact.append(fact[-1] * (i+1))

def calc(L):
    n = len(L)
    if n == 1: return 0
    a =  len([l for l in L if l < L[0]])
    return a * fact[n-1] + calc(L[1:])

N = int(input())
P = [int(a)-1 for a in input().split()]
Q = [int(a)-1 for a in input().split()]

print(abs(calc(P) - calc(Q)))

Measured memory_bytes: 3064
/**
 *    Author:  "Robin Singh" !!!!    
**/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define str string 
#define szz(v) ((int)(v).size())  
#define vi vector<int>
#define vll vector<ll>
#define fr(i, j, k) for(i = j; i < k; i++)
#define bk(i, j, k) for(i = j; i >= k; i--)
#define frit(it, a) for(__typeof((a).begin()) it = a.begin(); it != a.end(); ++it)
#define mem(ptr)  memset(ptr, 0, sizeof ptr)  // use fill() for value other than 0 //
#define rtn return 
#define time fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock()/CLOCKS_PER_SEC)
#define nl "\n"
#define INF 1LL<<61
#define inf 1<<30
#define dbg(x) (cerr << #x << ": " << x << "\n")
const long long mod = 1e9+7;

ll gcd(ll a,ll b) { return b==0 ? a : gcd(b, a%b); }
ll expo(ll x, ll y){ ll res = 1; x = x % mod;  while (y > 0) { if (y & 1)res = (res*x) % mod; y = y>>1;x = (x*x) % mod;}return res;}
void matmul(ll a[][2], ll b[][2]) { ll tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; }
ll fibo(int n)    // returns nth fibonacci number, also S(n) = f(n+2)-1
{ if(n == 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= 1; matmul(T, T); } return res[1][1]; }

const int nn = 1e5 + 10;
int dp[nn];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    fill(dp, dp+nn, 1e9);
    dp[0] = 0;
    for(int i=0; i<nn-1; i++){
        dp[i+1] = min(dp[i+1], dp[i]+1);
        for(int j=6; i+j <nn; j *= 6){
            dp[i+j] = min(dp[i+j], dp[i]+1);
        }
        for(int j=9; i+j <nn; j *= 9){
            dp[i+j] = min(dp[i+j], dp[i]+1);
        }
    }
    int n;
    cin >> n;
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 400005
#define ll long long
using namespace std;
struct edge
{
	int u, v, c;
	edge *rev;
	edge *next;
}pool[maxn * 10], *h[maxn];
int egcnt = 0;
void addedge(int u, int v, int c, int tp)
{
	edge *new1 = &pool[egcnt++];
	new1->u = u, new1->v = v, new1->c = c;
	
	edge *new2 = &pool[egcnt++];
	new2->u = v, new2->v = u, new2->c = c * tp;
	
	new1->rev = new2, new2->rev = new1;
	new1->next = h[u], h[u] = new1;
	new2->next = h[v], h[v] = new2;
}
int level[maxn], q[maxn], fr, ed;
int s, t;
void bfs()
{
	fr = ed = 0;
	memset(level, -1, sizeof(level));
	level[s] = 1, q[ed++] = s;
	while(fr < ed)
	{
		for(edge *p = h[q[fr]]; p; p = p->next)
		{
			if(!p->c || level[p->v] != -1) continue;
			level[p->v] = level[q[fr]] + 1, q[ed++] = p->v;
		}
		fr++;
	}
}
ll dfs(int a, ll flow)
{
	if(!flow) return 0;
	if(a == t) return flow;
	ll nf = 0;
	for(edge *p = h[a]; p; p = p->next)
	{
		if((level[p->v] != level[a] + 1) || (p->c <= 0)) continue;
		int nflow = dfs(p->v, min(flow - nf, (ll)p->c));
		nf += nflow, p->c -= nflow, p->rev->c += nflow;
	}
	if(!nf) level[a] = -1;
	return nf;
}
const ll inf = 1e18;
ll dinic()
{
	ll ans = 0;
	while(1)
	{
		bfs();
		ll nans = dfs(s, inf);
		if(!nans) break;
		ans += nans;
	}
	return ans;
}
int n;
int p[2][maxn];
int fl[2][maxn], bl[2][maxn];
int w[maxn]; // 不动惩罚 
int tp[maxn], cnt;
int main()
{
	cin >> n;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < n; j++)
			scanf("%d", &p[i][j]);
		for (int j = 0; j < n; j++) {
			if (fl[i][j]) continue;
			int ncnt = 0;
			q[ncnt++] = j;
			while (1) {
				int nx = p[i][q[ncnt - 1]];
				if (nx == j) break;
				q[ncnt++] = nx;
			}
			for (int k = 0; k < ncnt; k++)
				bl[i][q[k]] = cnt, 
				fl[i][q[k]] = 1;
			tp[cnt] = i;
			cnt++;
		}
	}
	int ans = n;
	for (int i = 0; i < n; i++) {
		if (p[0][i] == i && p[1][i] == i) ans--;
		else if (p[0][i] == i)
			w[bl[1][i]]++;
		else if (p[1][i] == i)
			w[bl[0][i]]++;
		else {
			int ntp = 0;
			if (p[0][i] == p[1][i]) ntp = 1;
			addedge(bl[0][i], bl[1][i], 1, ntp);
		}
	}
	s = cnt + 1, t = cnt + 2;
	for (int i = 0; i < cnt; i++)
		if (tp[i]) addedge(i, t, maxn, 0), addedge(s, i, maxn + w[i], 0);
		else addedge(i, t, maxn + w[i], 0), addedge(s, i, maxn, 0);
	ll nans = dinic() - 1ll * cnt * maxn;
	ans -= nans;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 34304
// C.

#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  int a[2][101] = {}, dp[2][101] = {};
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  }
  for (int j = n - 1; j >= 0; --j) {
    dp[1][j] = a[1][j] + dp[1][j + 1];
    dp[0][j] = a[0][j] + max(dp[1][j], dp[0][j + 1]);
  }
  cout << dp[0][0] << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        char[] data = Console.ReadLine().ToCharArray();
        for(int i = 0,count = data.Length;i<count;i++){
            if (char.IsUpper(data[i]))
            {
                data[i] = char.ToLower(data[i]);
            }
            else if (char.IsLower(data[i]))
            {
                data[i] = char.ToUpper(data[i]);
            }
        }
        Console.WriteLine(data);
    }
}

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

using namespace std;

string J(const string& s)
{
    int lasti = s.size() - 1;
    return s[lasti] + s.substr(0, lasti);
}

string C(const string& s)
{
    return s.substr(1) + s[0];
}

string E(const string& s)
{
    int size = s.size();
    int hsize = size / 2;
    if(size&1) return s.substr(hsize+1) + s[hsize] + s.substr(0, hsize);
    else return s.substr(hsize) + s.substr(0, hsize);
}

string A(const string& s)
{
    return string(s.rbegin(), s.rend());
}

string P(const string& s)
{
    string r;
    for(basic_string<char>::const_iterator i=s.begin(); i!=s.end(); i++)
    {
        r.push_back(('0'<=*i && *i<='9') ? (*i - '0' + 9) % 10 + '0' : *i);
    }
    return r;
}

string M(const string& s)
{
    string r;
    for(basic_string<char>::const_iterator i=s.begin(); i!=s.end(); i++)
    {
        r.push_back(('0'<=*i && *i<='9') ? (*i - '0' + 1) % 10 + '0' : *i);
    }
    return r;
}



int main()
{
    string (*op[128])(const string&);
    op['J'] = J;
    op['C'] = C;
    op['E'] = E;
    op['A'] = A;
    op['P'] = P;
    op['M'] = M;

    int n;
    cin >> n;
    while(n--)
    {
        string cmd, text;
        cin >> cmd >> text;
        for(basic_string<char>::reverse_iterator i=cmd.rbegin(); i!=cmd.rend(); i++)
        {
            text = op[*i](text);
        }
        cout << text << endl;
    }
}

Measured memory_bytes: 3092
h,w,d=map(int,input().split())
box=list(list(map(int,input().split())) for i in range(h))
q=int(input())
order=[list(map(int,input().split())) for i in range(q)]

S=[0]*(h*w+1)
add={}

for i in range(h):
    for j in range(w):
        add[box[i][j]]=[i,j]

for k in range(d+1,h*w+1):
    x,y=add[k]
    i,j=add[k-d]
    S[k]=S[k-d]+abs(x-i)+abs(y-j)

for s,g in order:
    print(S[g]-S[s])

Measured memory_bytes: 47716
//TINY_OUNCE911666
// You are not prepared!

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

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;

const int INF = 1e9+7;

int32_t main() {
	_upgrade
	
	int n, k;
	cin >> n >> k;
	
	vector<int> a(n), dp(n, INF);
	for (int& x : a) {
		cin >> x;
	}
	
	dp[0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i+1; j <= i+k; j++) {
			if (j < n) {
				dp[j] = min(dp[j], dp[i] + abs(a[i]-a[j]));
			}
		}
	}
	
	cout << dp[n-1] << "\n";
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iomanip>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define KETA 40

using namespace std;

typedef long long  ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


ll a[200002];
ll m1=0,m2=0;

int main() {

	ll n;
	cin>>n;

	rep(i,n){
		cin>>a[i];
		if(m1<=a[i]){
			m2=m1;
			m1=a[i];
		}else if(m2<=a[i]){
			m2=a[i];
		}
	}
	rep(i,n){
		if(a[i]<m1)cout<<m1<<endl;
		else cout<<m2<<endl;
	}

	return 0;

}


Measured memory_bytes: 3200
N, M, Q = map(int, input().split())

A = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    A[L][R] += 1

for i in range(1, N + 1):
    for j in range(1, N + 1):
        A[i][j] += A[i][j - 1]
for j in range(1, N + 1):
    for i in range(1, N + 1):
        A[i][j] += A[i - 1][j]

ans = []
for _ in range(Q):
    p, q = map(int, input().split())
    p -= 1
    ans.append(A[q][q] - A[q][p] - A[p][q] + A[p][p])
print(*ans, sep='\n')


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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int INF = 0x3f3f3f3f;
const ll  LINF = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

void solve(){
	int k,acc=0;
	cin>>k;
	for(int i=1;i<=k;++i){
		acc = (10*acc + 7);
		acc%=k;
		if(acc==0){
			cout<< i << endl;
			return;
		}
	}
	cout << -1 << endl;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>

using namespace std;

class Solution {
public:
	/* time: O(n), space: O(1) */
	bool tapDance(const string& s) {
		const int n = s.size();
		for (int i = 1; i <= n; ++i) {
			const char c = s[i - 1];
			if (i % 2) {
				if (c == 'L')
					return false;
			} else {
				if (c == 'R')
					return false;
			}
		}
		return true;
	}
};

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

	Solution sol;
	bool ans = sol.tapDance(s);
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int c=(N-N%10)/10;
  if (c%111==0) {
    cout<<"Yes"<<endl;
  }
  else if((N%1000)%111==0){
  cout<<"Yes"<<endl;
  }
  else{
  cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<cstdio>
struct r{
	int x,y;
}b[10050];
int n,sum,vis[105],mp[105][105],cnt;
int main(){
	scanf("%d",&n);
	sum=n*(n+1)/2;
	if (!(sum%2)){
		sum/=2;
		for (int i=n;i>=1;i--)if (sum>=i)vis[i]=1,sum-=i;
		for (int i=1;i<=n;i++)if (vis[i])
			for (int j=1;j<=n;j++)if (!vis[j])b[++cnt]=(r){i,j}; 
	}
	else {
		if ((n&1))for (int i=1;i<=n;i++){
		if (i<=n/2)mp[i][n-i]=1;}
		else 
		for (int i=1;i<=n;i++)if (i<=n/2)
		mp[i][n-i+1]=1;
		for (int i=1;i<=n;i++)
			for (int j=i+1;j<=n;j++)if (!mp[i][j])b[++cnt]=(r){i,j};
	}
	printf("%d\n",cnt);
	for (int i=1;i<=cnt;i++)printf("%d %d\n",b[i].x,b[i].y);
} 

Measured memory_bytes: 256
/*
ID: htc9811
LANG: C++
TASK:
*/

//#define Online
#define LOCAL
//#define debug
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
using namespace std;
const string TASK="";
vector<int> _V(int a[],int _n){vector<int> _v;for(int i=0;i<_n;i++) _v.push_back(a[i]);return _v;}
vector<long long> _V(long long a[],int _n){vector<long long> _v;for(int i=0;i<_n;i++) _v.push_back(a[i]);return _v;}
vector<string> _V(string a[],int _n){vector<string> _v;for(int i=0;i<_n;i++) _v.push_back(a[i]);return _v;}
inline string _IN(){return TASK+".in";}
inline string _OUT(){return TASK+".out";}

const int N=105;
int n,m,ans;
int v[N],w[N];
int dp[N][N][3*N];

int main(){
	#ifdef Online
	freopen(_IN().c_str(),"r",stdin);
	freopen(_OUT().c_str(),"w",stdout);
	#endif
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) scanf("%d%d",w+i,v+i);
	for(int i=0;i<n;i++) for(int j=0;j<=i;j++) for(int k=0;k<=3*j;k++){
		dp[i+1][j][k]=max(dp[i][j][k],dp[i+1][j][k]);
		dp[i+1][j+1][k+w[i]-w[0]]=max(dp[i+1][j+1][k+w[i]-w[0]],dp[i][j][k]+v[i]);
	}
//	for(int i=0;i<=n;i++) for(int j=0;j<=i;j++) for(int k=0;k<=3*j;k++) cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
	for(int i=0;i<=n;i++) for(int k=0;k<=3*i;k++){
		long long W=k+1LL*w[0]*i;
		if(W<=m) ans=max(ans,dp[n][i][k]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 11392
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
#define INF 1e9+7
#define PI 3.141592653
using namespace std;

int main(){
    int n;
    cin>>n;
    int a[n];
    pan(i,n) cin>>a[i];
    sort(a,a+n);
    // pan(i,n)cout<<*(a+i)<<endl;
    int ans=0;
    vi v;
    int i=0;
    while(i<n){
        int cc=a[i],f=0;
        while(i<n && a[i]==cc) {f++;i++;}
        ans+=f%2;
    }
    cout<<ans;
}

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

int main(int argc, char *argv[]){
  int n;
  while(std::cin >> n, n){
    vector<int> a(n);
    unordered_map<int, int> um;
    for (int i = 0; i < n; i++) {
      std::cin >> a[i];
    }
    for (int i = 0; i < a.size(); i++) {
      um[a[i]]++;
    }
    int ans = -1;
    for (auto i:um) {
      if(i.second > a.size()/2)ans = i.first;
    }
    if(ans == -1)std::cout << "NO COLOR" << std::endl;
    else std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 9620
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
 }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
ll dp[400][400];
int main(){
  ll n,m;
  cin>>n;
  memset(dp,-1,sizeof(dp));
  dp[0][0]=0;
  vll s(n),l(n),p(n);
  rep(i,n){
    cin>>s[i]>>l[i]>>p[i];
  }
  cin>>m;
  vll w(m);
  rep(i,m) cin>>w[i];
  rep(i,n){
    rep(j,397){
      dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
      for(int k=s[i];k<=l[i];k++){
        if(j>=k&&dp[i+1][j-k]>=0){
          dp[i+1][j]=max(dp[i+1][j-k]+p[i],dp[i+1][j]);
        }
      }
    }
  }
  rep(i,m){
    if(dp[n][w[i]]<0){
      COUT(-1);
      return 0;
    }
  }
  rep(i,m){
    COUT(dp[n][w[i]]);
  }
}


Measured memory_bytes: 4364
n = int(input())
a = list(map(int,input().split()))

i = 0
gapsum = 0
max = a[0]
for i in range(n):
    if a[i] < max:
        gap = max - a[i]
        gapsum += gap
    elif a[i] > max:
        max = a[i]
    i += 1

print(gapsum)

Measured memory_bytes: 32100
#include <iostream>


using namespace std;


int main()
{
	ios_base :: sync_with_stdio(false);
	int n = 0;
	cin >> n;
	int q = n % 10;
	if (q == 3) {
		cout << "bon";
	} else if (q == 0 || q == 1 || q == 6 || q == 8) {
		cout << "pon";
	} else {
		cout << "hon";
	}
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
  
int main()
{
    int N;
    cin >> N;
    vector<int> A(N + 1), visited(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    for (int i = 1; i <= N; i++) 
    {
        visited[A[i]] += i;
    }
    for (int i = 1; i <= N; i++)
    {
        cout << visited[i] << " ";
    }
}

Measured memory_bytes: 1536