akhauriyash/Code-Regression huggingface dataset:
N=int(input())
A=list(map(int,input().split()))
CUSUM=[0]*(N+2)
if N > 2:
  for i in range(N):
    if i == 0:
      CUSUM[1] = abs(A[0])
    else:
      CUSUM[i+1] = abs(A[i-1] - A[i])
  CUSUM[N+1] = abs(A[N-1])
  M = sum(CUSUM)
  #print(CUSUM)
  for i in range(N):
    if i == 0:
      ANS =  M - CUSUM[i+1] - CUSUM[i+2] + abs(A[i+1])
    elif i == N-1:
      ANS = M - CUSUM[-1] - CUSUM[-2] + abs(A[i-1])
    else:
      ANS = M - CUSUM[i+1] - CUSUM[i+2] + abs(A[i-1] - A[i+1])
    print(ANS)
else:
  print(abs(A[1])*2)
  print(abs(A[0])*2)

Measured memory_bytes: 14048
#include<cstdio>

int main(){
  int n;
  scanf("%d",&n);
 
  bool card[4][13];
  for(int i = 0; i < 4; i++){
      for(int j = 0; j < 13; j++){
        card[i][j] = false;
      }
  }
  
  for(int i = 0; i < n ; i++){
     char c;
     scanf("\n%c",&c);

     int x;
     scanf("%d",&x);
     //ここまで情報受け取り
      if(c == 'S'){
        card[0][x - 1] = true;
      }
      else if(c == 'H'){
        card[1][x - 1] =  true;
      }
      else if(c == 'C'){
        card[2][x - 1] = true;
      }
      else if(c  == 'D'){
        card[3][x - 1] = true;
      }
      
  }

  //出力
  for(int i = 0; i < 4; i++){
    for(int j = 0; j < 13; j++){
    //card[i][j]はfalseって決めているから
     if(!card[i][j]){
       if(i == 0){
        printf("S %d\n",j + 1);
       }
       else if(i == 1){
        printf("H %d\n",j + 1);
       }
       else if(i == 2){
        printf("C %d\n",j + 1);
       }
       else if(i == 3){
         printf("D %d\n",j + 1);
       }
     }
    }
  }
  
  
  
  return 0;

}



Measured memory_bytes: 2604
import java.util.Scanner;

public class Main {
	
	static Scanner scan;
	
	public static void main(String[] main) {
		scan = new Scanner(System.in);
		
		// Get the input number of array's elements.
		final int n = scan.nextInt();
		
		// Get the input array.
		int list[] = new int[n];
		for(int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		
		// Calculate the max profit.
		int max = list[1] - list[0];
		int key = list[0];
		for(int i = 0; i < n-1; i++) {
			for(int j = i+1; j < n; j++) {
				if(key < list[i]) break;
				if(max < list[j] - list[i]) {
					max = list[j] - list[i];
					key = list[i];
				}
			}
		}

		// Output the result.
		System.out.println(max);
	}
}



Measured memory_bytes: 101284
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&b==c)
  {
    cout<<"No";
  }
  else if(a==b || b==c ||c==a)
  {
    cout<<"Yes";
  }
  else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  rep(i, n) {
    int h;
    cin >> h;
    if (h >= k) ans++;
  }
  cout << ans << endl;
  
  return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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; }

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll n,m; 
vpll G[1000005];
ll dist[1000005];
bool visited[1000005];

void dfs(ll v){
  visited[v]=true;
  for(auto np: G[v]){
    ll nv=np.first, nc=np.second;
    if(visited[nv]){
      if(dist[nv]!=dist[v]+nc){
        // cout<<v<<" "<<nv<<" "<<nc<<" "<<dist[v]<<" "<<dist[nv]<<endl;
        cout<<"No"<<endl;
        exit(0);
      }
    }else{
      dist[nv]=dist[v]+nc;
      dfs(nv);
    }
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>m;
  rep(i,m){
    ll a,b,c; cin>>a>>b>>c;
    a--,b--;
    G[a].emplace_back(b,c);
    G[b].emplace_back(a,-c);
  }
  memset(dist,-1,sizeof(dist));
  rep(i,n){
    // cout<<i<<endl;
    if(visited[i]) continue;
    dist[i]=0;
    dfs(i);
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 43776
/**
*    created: 16.07.2020 01:54:25
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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 long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    map<int,int> mp;
    rep(i,3) {
        int a; cin >> a;
        mp[a]++;
    }
    if (mp[5] == 2 && mp[7] == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3632
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>


using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




/*
class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d, e, H, W, L;
ll A[2][100005] = {};
ll B[2][100005] = {};
ll C[200005] = {};
bool f, ff;
string S;
set <long long>sll;
pl bufpl;
vector <long long>vl[3];
vector <pl>vpl;
vector <string> vs;
set<ll> llset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}



ll minn, maxx;
double ansa;
bool fl[30] = {};

string ss, sss;

int main() {


	cin >> S;
	a = 10000;
	

	for (int i = 0; i < S.size(); i++) {
		fl[S[i] - 'a'] = true;
	}

	for (int i = 0; i < 26; i++) {
		if (fl[i]) {
			ss = S;
			sss = S;
			while (true) {
				e = 0;
				for (int j = 0; j < sss.size(); ) {
					e++;
					sss = ss;

					for (int k = 0; k < sss.size() - 1; k++) {
						if (sss[k] - 'a' == i || sss[k + 1] - 'a' == i) {
							ss[k] = i + 'a';
						}
						else {
							ss[k] = sss[k];
						}
					}

					ss.pop_back();
					f = true;
					for (int k = 0; k < ss.size(); k++) {
						if (ss[k] - 'a' != i) {
							f = false;
						}
					}

					if (f) {
						if (e < a) {
							a = e;
						}
						break;
					}

					if (ss.empty()) {
						break;
					}

				}
				break;
			}

		}
	}

	b = 0;
	for (int i = 0; i < 26; i++) {
		if (fl[i]) {
			b++;
		}
	}

	if (b == 1) {
		a = 0;
	}

	cout << a << endl;

	return 0;

}


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

int main() {
  int N;
  cin >> N;
  int r0, r1;
  cin >> r0 >> r1;
  int buy, sell;
  buy = r0;
  sell = r1;
  int maxp = r1-r0; 
  int trend = maxp;
  int prev_r = r1;
  for (int i = 2; i < N; i++) {
    int r;
    cin >> r;
    int d = r - prev_r;
    if (trend < 0 && d >= 0 && buy > prev_r) {  // SOKO
      buy = prev_r;
    }
    if (r - buy > maxp) maxp = r-buy;
    trend = d;
    prev_r = r;
  }
  cout << maxp << endl;
}


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

int main() {
  int64_t H;
  cin >> H;
  
  int64_t counter = 0;
  int64_t shosu = log2(H) - (int)log2(H);
  for (int64_t i = 0; i < floor(log2(H)) + 1 - shosu; i++) {
    counter += pow(2, i);
  }

  cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
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; }


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> a(N+1);
    REP(i,N) cin >> a[i];
    int cnt = 0;
    REP(i,N){
        if(a[i] == a[i+1]){
            a[i+1] = 100010;
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#define LL long long
using namespace std;

int n,tnow=1,num;
int a[1000010];
int vis[1000010];

int now,fh;char ch;
inline int get_num()
{
	now=0;fh=1;ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')fh=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){now=(now<<1)+(now<<3)+ch-'0';ch=getchar();}
	return now*fh;
}

int main()
{
	n=get_num();
	for(int i=1;i<=n;i++)a[i]=get_num();
	while(1)
	{
		if(vis[tnow]!=0)break;
		vis[tnow]=num++;
		tnow=a[tnow];
	}
	if(vis[2]==0)puts("-1");
	else printf("%d\n",vis[2]);
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
using namespace std;
#define rep(i,q) for(int i = 0; q > i; i++)
int main(){
  int N;cin >> N;
  int A[N];
  rep(i,N)cin >> A[i];
  int kekka = 0;
  rep(i,N)if(i+1 == A[A[i]-1])kekka++;
  cout << kekka/2  << endl;
}

Measured memory_bytes: 640
from collections import defaultdict


def my_pow(x,n):
    ret = 1
    mod = 10**9+7
    for _ in range(n):
        ret = (ret*x)%mod
    return ret
    

def check():
    N = int(input())
    A = [int(i) for i in input().split()]
    count = defaultdict(int)
    
    if N%2==0:
        for a in A:        
            if a%2==0:
                return 0
            count[a] += 1
        for cnt in count.values():
            if cnt != 2:
                return 0
        return my_pow(2,len(count))
    else:
        for a in A:
            if a%2!=0:
                return 0
            count[a] += 1
        if count[0] != 1:
            return 0
        count[0] = 2
        for cnt in count.values():
            if cnt != 2:
                return 0
        return my_pow(2,len(count)-1)
      
print(check())

Measured memory_bytes: 14812
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];

    unordered_map<ll, int> c;
    rep(i, n) c[A[i]] = 0;
    rep(i, n) c[A[i]]++;

    int sum = 0;
    for (auto kv: c) {
        if (kv.second % 2 == 1)
            sum++;
    }    

    put(sum);
    
    return 0;
}

Measured memory_bytes: 8020
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var D = cin.ReadInt;
            var X = cin.ReadInt;

            var A = new int[N];
            for (int i = 0; i < N; i++)
            {
                A[i] = cin.ReadInt;
            }

            var ans = 0;

            for (int i = 0; i < N; i++)
            {
                var tmp = 1 + (D - 1) / A[i];
                ans += tmp;
            }

            ans += X;

            WriteLine(ans);

        }
    }

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

Measured memory_bytes: 13268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace contest13
{
    class Program
    {
        static void Main(string[] args)
        {
            Stack<string> car_list = new Stack<string>();
            while (true)
            {
                var read_line_origin = Console.ReadLine();
                if (read_line_origin == null)
                {
                    break;
                }

                //FIFO
//                int input = int.Parse(read_line_origin);


                //0なら車をだす
                //それ以外ならスタックに入れる

                if (read_line_origin == "0")
                {
                    if (car_list.Count == 0)
                    {
                        return;
                    }
                    else
                    {
                        string car = car_list.Pop();
                        Console.WriteLine(car.ToString());
                    }
                }
                else
                {
                    car_list.Push(read_line_origin);
                }

                

            }
        }
    }
}

Measured memory_bytes: 5588
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
m = 0
ans = 0
P = []
for a,b in zip(A,B):
    if a - b < 0:
        m += b-a
        ans += 1
    elif a - b > 0:
        P.append(a-b)
P.sort(reverse = True)
if m <= 0:
    print(ans)
else:
    for p in P:
        m -= p
        ans += 1
        if m <= 0:
            print(ans)
            break
    else:
        print(-1)


Measured memory_bytes: 81584
#include <iostream>

using namespace std;

int N, M;
int s[10][10], p[10];

int next_combination(int combi){
	const int x = combi & -combi;
	const int y = x + combi;
	return y | (((combi & ~y) / x) >> 1);
}

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

	for (int i = 0; i < M; i++){
		int k;
		cin >> k;
		for (int j = 0; j < k; j++){
			int temp;
			cin >> temp;
			s[i][temp - 1] = 1;
		}
	}
	for (int i = 0; i < M; i++){
		cin >> p[i];
	}

	int ans = 0;
	for (int count = 0; count < 1 << N; count++){
		int state[10] = {0};
		for (int i = 0, temp = count; i < N; i++){
			if(temp & 1){
				for (int j = 0; j < M; j++){
					if(s[j][i]){
						state[j] = (state[j] + 1) % 2;
					}
				}
			}
			temp >>= 1;
		}

		bool flag = true;
		for (int j = 0; j < M; j++){
			if(state[j] != p[j]){
				flag = false;
				break;
			}
		}
		if(flag){
			ans++;
		}
	}

	cout << ans << endl;
	return 0;
}

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

int main() {
    ll X;
    cin >> X ;
    ll i = 0 , m = 100;
    while(m < X){
        m *= 1.01;
        i += 1;
    }
    cout << i << endl;
    return 0;
}

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

int main(){
   int N;
   cin >> N;
   vector<int> B(N-1);
   for (int i=0; i<N-1; i++){
      cin >> B.at(i);
   }
   vector<int> Ans(N);
   Ans.at(N-1) = B.at(N-2);
   Ans.at(0) = B.at(0);
   for (int i=N-2; i>0; i--){
      if (B.at(i) > B.at(i-1)){
         Ans.at(i) = B.at(i-1);
      } else{
         Ans.at(i) = B.at(i);
      }
   }
   cout << accumulate(Ans.begin(), Ans.end(), 0) << endl;

}



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

int main() {
    long long n;
    cin >> n;
    vector<long long> a(n+1);
    long long sum=0;
    for ( int i=0; i<n; i++ ) {
        cin >> a[i];
        sum+=a[i];
    }
    long long m=(long long)n*(n+1)/2;
    if ( sum%m ){
        cout << "NO" << '\n';
        return 0;
    }
    m = sum/m;
    a[n]=a[0];
    // (k-d)/n = x
    sum = 0;
    for ( int i=0; i<n; i++ ) {
        // cout << a[i+1] << ' ' << a[i] << '\n';
        long long d=(a[i+1] - a[i]);
        if ( m<d || (m-d)%n ){
            cout << "NO" << '\n';
            return 0;
        }
    }
    cout << "YES" << '\n';
    return 0;
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 0;
    vector<int> rsum(n+1, 0);
    vector<int> gsum(n+1, 0);
    vector<int> bsum(n+1, 0);

    rep(i, n){
        if (s[i]=='R') rsum[i+1] = rsum[i] + 1;
        else rsum[i+1] = rsum[i];

        if (s[i]=='G') gsum[i+1] = gsum[i] + 1;
        else gsum[i+1] = gsum[i];

        if (s[i]=='B') bsum[i+1] = bsum[i] + 1;
        else bsum[i+1] = bsum[i];
    }


    rep(i, n-2){
        char ci = s[i];
        for(int k=n-1; k>i+1; k--){
            char ck = s[k];
            if (ci==ck) continue;
            if ((ci=='R' and ck=='G') or (ci=='G' and ck=='R')){
                ans += bsum[k+1]-bsum[i];
            }else if ((ci=='R' and ck=='B') or (ci=='B' and ck=='R')){
                ans += gsum[k+1]-gsum[i];
            }else if ((ci=='G' and ck=='B') or (ci=='B' and ck=='G')){
                ans += rsum[k+1]-rsum[i];
            }
            if ((k-i)%2==0){
                int mid = (k-i)/2 + i;
                if(s[mid]!=ci and s[mid]!=ck){
                    ans--;
                }
            }
        }

    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
H, W, M = map(int, input().split())
h = [0 for _ in range(H+1)]
w = [0 for _ in range(W+1)]
hmax = 0
wmax = 0
Q = []
for _ in range(M):
  a, b = map(int, input().split())
  Q.append((a, b))
  h[a] += 1
  hmax = max(hmax, h[a])
  w[b] += 1
  wmax = max(wmax, w[b])
h_ok = False
w_ok = False
hm = [False for _ in range(H+1)]
wm = [False for _ in range(W+1)]
h_cnt = 0
w_cnt = 0
hw_cnt = 0
for a, b in Q:
  if not hm[a] and h[a] == hmax:
    hm[a] = True
    h_cnt += 1
  if not wm[b] and w[b] == wmax:
    wm[b] = True
    w_cnt += 1
  if h[a] == hmax and w[b] == wmax:
    hw_cnt += 1
if h_cnt*w_cnt - hw_cnt > 0:
  print(hmax+wmax)
else:
  print(hmax+wmax-1)


Measured memory_bytes: 157564
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  if(n/10==0){
    cout << n << endl;
    return 0;
  }
  if(n/100==0){
    cout << 9 << endl;
    return 0;
  }
  if(n/1000==0){
    cout << 9+n-99 << endl;
    return 0;
  }
  if(n/10000==0){
    cout << 9+900 << endl;
    return 0;
  }
  if(n/100000==0){
    cout << 9+900+n-9999 << endl;
    return 0;
  }
  else cout << 90909 << endl;
}  


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
b.append(0) #n+1番目を作っとく
num=0
c=0
for i in range(n):
    if a[i]<=c:
        num+=a[i]
        c=b[i]
    else:
        a[i]-=c
        num+=c
        if b[i]>=a[i]:
            num+=a[i]
            c=b[i]-a[i]
        else:
            num+=b[i]
            c=0
        
if b[n]+c>=a[n]:
    num+=a[n]
else:
    num+=b[n]+c
print(num)

Measured memory_bytes: 18476
#include <bits/stdc++.h>
using namespace std;
int main() {
  #define int long long
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  string s;
  int n;
  cin >> n;
  cin >> s;
  vector<vector<int>> t(26,vector<int>(n+1,0));
  auto upd = [&](int i,int x,int y){for(;x<=n;x+=x&-x) t[i][x]+=y;};
  auto get = [&](int i,int x){int rt(0);for(;x;x-=x&-x) rt +=t[i][x];return rt;};
  for(int i=0;i<n;i++) {
    upd(s[i]-'a',i+1,true);
  }
  int q;
  cin >> q;
  while(q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int pos; char c;
      cin >> pos >> c;
      upd(s[pos-1]-'a',pos,-1);
      s[pos-1] = c;
      upd(s[pos-1]-'a',pos,1);
    } else {
      int l,r;
      cin >> l >> r;
      int ans = 0;
      for(int i=0;i<26;i++) {
        if (get(i,r) - get(i,l-1) > 0) {
          ans ++;
        }
      }
      cout << ans << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 106396
#include <bits/stdc++.h>
using namespace std;
int pre[104];
int main()
{
       int n,m,x,s1=0,s2=0;
       cin>>n>>m>>x;
      int arr[n+4];
      for(int i=0;i<m;i++)
      {
          cin>>arr[i];
          pre[arr[i]]=1;
      }

      for(int i=0;i<=x;i++){
      s1+=pre[i];
      }
      for(int i=x;i<=n;i++){
      s2+=pre[i];
      }
      if(s1<s2)
        cout<<s1;
      else cout<<s2;
    return 0;
   }

Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <stdlib.h>
#include <fstream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

bool test = true;
#define log(x) cout << "#x" << " : " << x << "\n";

int main()
{
    FIO;
    int t;
    cin >> t;
    cout << ( (t >= 30) ? "Yes" : "No" ) << "\n";
}



Measured memory_bytes: 3628
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N; cin >> N;

	int a[100];
	a[0] = 2;
	a[1] = 1;
	eFOR(i, 2, N)a[i] = a[i - 1] + a[i - 2];
	cout << a[N] << endl;

	return 0;
}



Measured memory_bytes: 256
import math
from functools import reduce

def gcd(*numbers):
	return reduce(math.gcd, numbers)

K = int(input())
S=0
for i in range(1,K+1):
	for h in range(i,K+1):
		for g in range(h,K+1):

			if i==h and h==g:
				S+=gcd(g,h,i)
			elif i==h or h==g or g==i:
				S+=3*gcd(g,h,i)
			else:
				S+=6*gcd(g,h,i)
			
print(S)

Measured memory_bytes: 9632
fun main() {
    var n = readLine()!!.toLong()
    var s = StringBuilder()

    do {
        val mod = n % 26
        if (mod != 0L) {
            s.append('a' + ((mod).toInt()) - 1)
            n = (n - mod) / 26
        } else {
            s.append('z')
            n = (n - 26) / 26
        }
    } while (n != 0L)

    println(s.reverse())
}

Measured memory_bytes: 34572
#include <stdio.h>
int main(void){
    int n;
    scanf("%d",&n);

    double h;
    h=2.0000000;
    double a;

    if(n%2){
      a=((n+1.0)/h)/n;
    }else{
      a=0.5;   
    }

    printf("%f",a);
}

Measured memory_bytes: 1712
#include <stdio.h>

int main(void) {
    long a, b, tmp;

    scanf("%ld %ld", &a, &b);
    if (b>a) tmp=b, b=a, a=tmp;
    while (b!=0) {
        tmp=b;
        b=a%b;
        a=tmp;
    }
    printf("%ld\n", a);
    
    return 0;
}



Measured memory_bytes: 2104
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
INF = 10 ** 10
MOD = 10 ** 9 + 7
from heapq import heapify,heappop,heappush
input = sys.stdin.readline

def main():
    n = int(input())
    t,a = list(map(int,input().split()))
    dif = INF
    ans = -1
    h = list(map(int,input().split()))
    for i in range(n):
        if dif > abs(a - t + h[i] * 0.006):
            dif = abs(a - t + h[i] * 0.006)
            ans = i + 1
    print(ans)
if __name__=='__main__':
    main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std; 
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b&&b!=c)||(a==c&&c!=b)||(c==b&&b!=a))
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    ll n, k, sum=0LL;
    cin >> n >> k;
    vector<ll> a, f;
    rep(i, n){
        ll x;
        cin >> x;
        a.push_back(x);
        sum += x;
    }
    rep(i, n) {
        ll x;
        cin >> x;
        f.push_back(x);
    }
    if(sum<=k){
        cout << 0 << endl;
    }else{
        sort(a.begin(), a.end());
        sort(f.begin(), f.end());
        ll maxim=0;
        rep(i, n){
            maxim = max(maxim, a[i]*f[n-i-1]);
        }
        ll l=0, r=maxim;
        while(r-l>1){
            ll mid = (l + r) / 2LL;
            ll times=0;
            bool flag=true;
            rep(i, n){
                ll cost = mid / f[n-1LL-i];
                // cout << cost << endl;
                times += max(0LL, a[i]-cost);
                if(times>k){
                    l = mid;
                    flag = false;
                    break;
                }
            }
            if(flag){
                r = mid;
            }
            // cout << l << " : " << r << endl;
        }
        cout << r << endl;
    }
    return 0;
}

Measured memory_bytes: 7988
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

from decimal import Decimal

a,b=input().rstrip().split(" ")
u=Decimal(a)*Decimal(b)
#print(u)
print(int(u))
'''a=int(a)
b=float(b)
#print(b)
u=int(100*b)
#print(u)
print(int(a*b))
#print((a*u)//100)'''

Measured memory_bytes: 10092
N,M = map(int,input().split())
A = [input() for i in range(N)]
B = [input() for j in range(M)]
frd = N-M

def check(A,B,i,j):
    for yoko in range(M):
        for tate in range(M):
            if A[tate+i][yoko+j] != B[tate][yoko]:
                return False
    return True
    
for i in range(frd+1):
    for j in range(frd+1):
        if check(A,B,i,j):
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define itn int

int main(void){
    int n,m;
    cin >> n >> m;
    int h[n];
    for(int i = 0;i < n;i++){
        cin >> h[i];
    }
    int a[m],b[m];
    for(int i = 0;i < m;i++){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
    }
    
    int ans[1000001] = {};long long sum = 0;
    for(int i = 0;i < m;i++){
        ans[a[i]] = max(ans[a[i]],h[b[i]]);
        ans[b[i]] = max(ans[b[i]],h[a[i]]);
    }
    for(int i = 0;i < n;i++){
        if(h[i] > ans[i])sum++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 8696
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define int long long
#define double long double


using namespace std;
const int N = 501777;
int h1, m1;
int h2, m2;
int k;


signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	//freopen("input.txt", "r", stdin);
    cin >> h1 >> m1;
    cin >> h2 >> m2;
    cin >> k;
    m1 = m1 + h1 * 60;
    m2 = m2 + h2 * 60;
    cout << m2 - m1 - k << endl;
}


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

int main(){
	int N;
	cin >> N;
	int L[N];
	for(int i = 0; i < N; i++) cin >> L[i];
	sort(L, L+N);
	int sum = 0;
	for(int i = 0; i < N - 1; i++) sum+= L[i];
	if(L[N-1] < sum) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
n = int(input())
B = []
F = []
R = []
V = []
T = [[[0 for i in range(10)] for j in range(3)]for k in range(4)]
for i in range(n):
    b,f,r,v = map(int,input().split())
    T[b-1][f-1][r-1] += v
for i in range(4):
    for j in range(3):
        for k in range(10):
            print(" ",end="")
            print(T[i][j][k], end="")
        print()
    if i < 3:
        print("#"*20)



Measured memory_bytes: 5636
n=int(input())
l=list(map(int,input().split()))
ans=0
for a in l:
  for b in l:
    for c in l:
      if (a==b or b==c or a==c):
        continue
      if max([a,b,c])<a+b+c-max([a,b,c]):
        ans+=1
print(ans//6)


Measured memory_bytes: 9064
#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>;

int main(){
    int s, w; cin >> s >> w;
    if(w >= s) cout << "unsafe" <<endl;
    else cout << "safe" <<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	vector<lli> h(n);
	for(lli &x:h)cin>>x;
	sort(all(h));
	lli s=0;
	for(int i=0;i<n-k;i++){
		s+=h[i];
	}
	cout<<s<<endl;
}

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

const int INF=0x3f3f3f3f;
int a[55];

int main(){
    int n,idx1=1,idx2=1;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(a[i]<a[idx1]) {idx1=i;}
        if(a[i]>a[idx2]) {idx2=i;}
    }
    if(abs(a[idx2])>=abs(a[idx1])){
        cout<<2*n-1<<endl;
        for(int i=1;i<=n;i++){
            cout<<idx2<<" "<<i<<endl;
        }
        for(int i=1;i<n;i++){
            cout<<i<<" "<<i+1<<endl;
        }
    }
    else{
        cout<<2*n-1<<endl;
        for(int i=1;i<=n;i++){
            cout<<idx1<<" "<<i<<endl;
        }
        for(int i=n;i>1;i--){
            cout<<i<<" "<<i-1<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*
import java.math.*

fun main(args: Array<String>) {
    var (N, K) = readLine()!!.split(" ").map { it.toInt() }
//    var N = readLine()!!.toInt()
    val S = readLine()!!
//    val D = readLine()!!.split(" ").map { it.toLong() }

    for (i in 0 until N)
        print(if (i==K-1)S[i].toLowerCase() else S[i])
    println()
}


Measured memory_bytes: 37904
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double EPS = 1.0e-10;

void primeNumber(int N, vector<bool>& prime)
{
    prime.assign(N+1, true);
    prime [0] = prime[1] = false;
    for(int i=2; i*i<=N; i++){
        if(prime[i]){
            for(int j=i; i*j<=N; j++){
                prime[i*j] = false;
            }
        }
    }
}

int MAX = 500;
vector<int> prime;
map<long long, double> m;

void solve(int i, long long a, long long sum)
{
    m[a] = sum / (double) a;
    map<long long, double>::iterator it = m.find(a);
    while(it != --m.end()){
        map<long long, double>::iterator it2 = it;
        ++ it2;
        if(it2->second < it->second){
            m.erase(it2);
        }else{
            break;
        }
    }
    if(it != m.begin()){
        map<long long, double>::iterator it2 = it;
        -- it2;
        if(it2->second > it->second)
            m.erase(it);
    }

    if(i > prime.size())
        return;

    long long tmp = 1;
    long long sum2 = sum;
    for(;;){
        a *= prime[i];
        if(a > 1000000000000000LL)
            return;

        tmp *= prime[i];
        sum2 += sum * tmp;

        solve(i+1, a, sum2);
    }
}

int main()
{
    vector<bool> isPrime;
    primeNumber(MAX, isPrime);
    for(int i=0; i<=MAX; ++i){
        if(isPrime[i])
            prime.push_back(i);
    }

    solve(0, 1, 1);
    m[LLONG_MAX] = 0.0;

    for(;;){
        long long k;
        cin >> k;
        if(k == 0)
            return 0;

        map<long long, double>::iterator it = m.upper_bound(k);
        -- it;
        printf("%.10f\n", it->second);
    }
}

Measured memory_bytes: 1236
#include<stdio.h>
int main(void)
{
	int n,a,b,c,d,x,y;
	scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
	if(n % a==0){
		x= n / a;
	}
	else{
		x =(n / a)+1;
	}
	if(n % c==0){
		y =n / c;
	}
	else{
		y = (n / c)+1;
	}	
	if(x * b<=y * d){
		printf("%d\n", x * b);
	}
	else{
		printf("%d\n", y * d);
	}
	return 0;
}


Measured memory_bytes: 2140
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	int N;
	cin>>N;
	
	int sq=0;
	rep1(i,40000)if(i*i<=N) sq=i*i;
	cout<<sq;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end() 
using namespace std;
typedef long long ll;

const int N = 1e5 + 5;
ll a[N];
int n, x;

int main() {
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cin >> n >> x;
   for(int i=0; i<n; ++i) cin >> a[i];
   ll res = 0ll;
   for(int i=0; i<n-1; ++i) {
       if(a[i] + a[i+1] > x) {
           ll ext = (a[i] + a[i+1]) - x;
           res += ext;
           a[i+1] -= ext;
           a[i+1] = max(0ll, a[i+1]);
       }
   }
   cout << res << "\n";
   return 0;
} 


Measured memory_bytes: 1024
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int s1 = sc.nextInt();
   int s2 = sc.nextInt();
   int s3 = sc.nextInt();
   if(s1==s2) System.out.println(s3);
   else if(s2==s3) System.out.println(s1);
   else System.out.println(s2);
 }
}

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


#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define min(a,b) a<b?a:b
#define max(a,b) a>b?a:b
#define pb push_back
#define inf 1e9+11
typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;

void pre(){
}

void solve(){
	ll n,k;
	cin >> n >> k;
	ll h[n];
	rep(i,n) cin >> h[i];
	ll dp[n];
	memset(dp, inf, sizeof(dp));
	dp[0] = 0;
	rep(i,n-1){
		repA(j,i+1,i+k){
			if(j <= n-1){
				dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j])); 
			}
		}
	}
	cout << dp[n-1] << endl;

}
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	solve();	
	return 0;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll 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 mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

void solve(long long X, long long Y, long long Z, long long K, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C)
{
    RSORT(A);
    RSORT(B);
    RSORT(C);

    vector<ll> ans;
    for (int i = 0; i < X; i++)
    {
        for (int j = 0; j < Y; j++)
        {
            for (int k = 0; k < Z; k++)
            {
                if ((i + 1) * (j + 1) * (k + 1) <= K)
                {
                    ans.push_back(A[i] + B[j] + C[k]);
                }
                else
                {
                    continue;
                }
            }
        }
    }
    RSORT(ans);
    for (int i = 0; i < K; i++)
    {
        cout << ans[i] << endl;
    }
}

int main()
{
    long long X;
    scanf("%lld", &X);
    long long Y;
    scanf("%lld", &Y);
    long long Z;
    scanf("%lld", &Z);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> A(X);
    for (int i = 0; i < X; i++)
    {
        scanf("%lld", &A[i]);
    }
    std::vector<long long> B(Y);
    for (int i = 0; i < Y; i++)
    {
        scanf("%lld", &B[i]);
    }
    std::vector<long long> C(Z);
    for (int i = 0; i < Z; i++)
    {
        scanf("%lld", &C[i]);
    }
    solve(X, Y, Z, K, std::move(A), std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 1404
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	private static int n;

	public static void main(String[] args) {

		Main main = new Main();

		Set<Integer> set = new HashSet<>(5);
		int[][] arr = main.scan();
		int candies = 0;

		int f = 0;
		for (int i = 0; i < n; i++) {
			f += arr[0][i];
			for (int j = i; j < n; j++) {
				candies += arr[1][j];
			}
			set.add(f + candies);
			candies = 0;
		}

		System.out.println(Collections.max(set));
	}

	private int[][] scan() {

		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[][] arr = new int[2][n];
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				arr[i][j] = sc.nextInt();
			}
		}
		sc.close();
		return arr;
	}
}

Measured memory_bytes: 23764
import sys
raw_input = sys.stdin.readline
N,W = map(int,raw_input().split())
dp = [0 for x in range(W+1)]
for i in range(N):
    a,b = map(int,raw_input().split())
    for j in range(W,a-1,-1):
        dp[j] = max(dp[j],dp[j-a]+b)
print max(dp)

Measured memory_bytes: 33260
#include <iostream>

using LL = long long;

LL solve(LL n, LL s)
{
    int b = 2;
    for (; 1LL * b * b <= n; ++ b) {
        LL x = n;
        LL ss = 0;
        while (x) {
            ss += x % b;
            x /= b;
        }
        if (ss == s) {
            return b;
        }
    }
    if (n >= s) {
        for (int q = b; q >= 1; -- q) {
            LL xb = (n - s) / q + 1;
            if (xb >= 2 && n / xb + n % xb == s && n / xb / xb == 0) {
                return xb;
            }
        }
    }
    if (n == s) {
        return n + 1;
    }
    return -1;
}

int main()
{
    LL n, s;
    std::cin >> n >> s;
    std::cout << solve(n, s) << std::endl;
}


Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    H,W = MI()
    S = H*W

    def solve(H,W):
        ans = inf
        for h in range(H):
            if not (H-h)&1 or not W&1:
                piece = [h*W]
                piece.append(W*(H-h)/2)
                ans = min(ans, max(piece)-min(piece))
            else:
                if (H-h)&1:
                    piece = [h*W]
                    piece.append((H-h-1)*W/2)
                    piece.append((H-h+1)*W/2)
                    ans = min(ans, max(piece)-min(piece))
                if W&1:
                    piece = [h*W]
                    piece.append((W-1)*(H-h)/2)
                    piece.append((W+1)*(H-h)/2)
                    ans = min(ans, max(piece)-min(piece))
        return ans    

    ans1 = solve(H,W)
    ans2 = solve(W,H)

    print(int(min(ans1,ans2)))
if __name__ == '__main__':
    main()


Measured memory_bytes: 43484