akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
int n, k, q;
int a[1000006], b[1000006];
bool check(int l, int r){
	int ans = 0, cnt = 0, cnt2 = 0;
	for (int i = 1; i <= n; ++ i)
		if (a[i] < l){
			if (cnt >= k)
				ans += min(cnt2, cnt - k + 1);
			cnt = cnt2 = 0;
		}
		else{
			++ cnt;
			if (a[i] <= r)
				++ cnt2;
		}
	if (cnt >= k)
		ans += min(cnt2, cnt - k + 1);
	return ans >= q;
}
int bs(int lower, int l, int r){
	int ans = 2000000000;
	while (l <= r){
		int m = l + r >> 1;
		if (check(lower, b[m])){
			ans = b[m];
			r = m - 1;
		}
		else
			l = m + 1;
	}
	return ans;
}
int main(){
	cin >> n >> k >> q;
	for (int i = 1; i <= n; ++ i){
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b + 1, b + 1 + n);
	int ans = 2000000000;
	for (int i = 1; i <= n; ++ i)
		ans = min(ans, bs(b[i], i, n) - b[i]);
	cout << ans << endl;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n, m;

vector<LL> edges[110000];
LL vis[110000];

LL bip;
LL num[2];
LL numv;

LL ans = 0;
void dfs(LL v, LL color){
    if(vis[v] == color) return;
    if(vis[v] == 3-color){
        bip = 0;
        return;
    }
    num[color-1]++;
    numv++;
    vis[v] = color;
    for(LL j = 0; j < edges[v].size(); j++){
        dfs(edges[v][j], 3-color);
    }
}
int main(){
    for(LL i = 0; i < n; i++){
        vis[i] = 0;
    }
    cin >> n >> m;
    for(LL i = 0; i < m; i++){
        LL a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    ans -= m;
    for(LL i = 0; i < n; i++){
        if(vis[i]) continue;
        bip = 1;
        num[0] = num[1] = 0;
        numv = 0;
        dfs(i, 1);
        if(bip){
            ans += num[0] * num[1];
        } else {
            ans += numv*(numv-1)/2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 8192
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
Arr.shift();

let bfr = [];
for (let i=0; i<4; i++) {
    bfr.push([]);
    for (let j=0; j<3; j++) {
        bfr[i].push([]);
        for (let k=0; k<10; k++) {
            bfr[i][j].push(0);
        }
    }
}

for (i=0; i<Arr.length; i++) {
    let tenant = Arr[i].split(' ').map(Number);
    let b = tenant[0] - 1;
    let f = tenant[1] - 1;
    let r = tenant[2] - 1;
    let v = tenant[3];
    bfr[b][f][r] += v;
}

for (i=0; i<4; i++) {
    for(j=0; j<3; j++) {
        console.log(' ' + bfr[i][j].join(' '));
    }
    if (i !== 3) {
        console.log("####################");
    }
}

  


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

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

  if(a > b){
    int temp = a;
    a = b;
    b = temp;
  }

  int start = a,
      end   = a+w;

  int dist;
  if(start <= b && b <= end) dist = 0;
  else dist = min(abs(b-start), abs(b-end));

  cout << dist << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,29)-1;


int main() {
  int N, D; cin >> N >> D;
  int X[N][D]; rep(i,N) rep(j,D) cin >> X[i][j];
  int result = 0;
  rep(i,N) for (int j=i+1; j<N; j++) {
    int sum = 0;
    rep(k,D) sum += pow(X[i][k]-X[j][k],2);
    if (pow(floor(sqrt(sum)),2)==sum) result++;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


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

		int num, mode = 0;
		int nums[] = new int[100];

		for(int i = 0; i < 100; i++){
			nums[i] = 0;
		}

		while(sc.hasNext()){
			num = sc.nextInt();

			nums[num - 1]++;
			if(mode < nums[num -1]) mode = nums[num - 1];
		}

		for(int i = 0; i < 100; i++){
			if(nums[i] == mode) System.out.println(i + 1);
		}
	}
}

Measured memory_bytes: 12000
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#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>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll m = 1000000007;
#pragma GCC optimization ("O3")
const int N = 1000010;
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

ll f[2000010];

ll lcm(ll a,ll b)
{
  return (a*b)/__gcd(a,b);
}
ll binpow(ll a, ll b) {
     ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
 
ll find_ncr(ll n, ll r)
{
    ll m1=max(r,n-r);
    ll i,j,s,d=1,k;
    s=1;
 
    for(i=m1+1;i<=n;i++)
    {
        s=((s%m)*(i%m))%m;
    }
 
    m1=min(r,n-r);
 
    for(i=1;i<=m1;i++)
    {
        k=binpow(i,m-2);
        d=((d%m)*(k%m))%m;
    }
 
    k=(s%m*(d%m))%m;
 
    return k;
}

bool pall(string s)
{
  if(s.size() > 1)
  {
    for (int i = 0; i < s.size()/2; ++i)
    {
      if(s[i] != s[s.size()-i-1])
        return false;
    }
    return true;
  }
  else
    return true; 
}
int main()
{
  // int x = -1, y = 10000;
  // double z = 0.2;
  // string s2 = "beginner1010";
  // long long b = 1LL << 60;
    
  // // debug(x, y, z, s, b);
    
  // double aux = 1010.0;
  // string code = "code";
    
  // debug(code + "forces",-aux / 10 * 2.3);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string s,s1,s2;
  cin >> s;
  if (pall(s))
  {
    s1 = s.substr(0,(s.size()-1)/2);
    s2 = s.substr((s.size()+1)/2,s.size());
    if(pall(s1) && pall(s2))
      cout << "Yes\n";
    else
      cout << "No\n";
  }
  else
  {
    cout << "No";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    char pn;
    ll nm, nx, nd, ans;
    cin>>nm>>nx>>pn>>nd;
    nx = (nx*100) + nd;
    ans = (nm*nx)/100;
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 19;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}



void solve() {
	int n; cin >> n;
	vector<ll> x(n), y(n);
	vector<ll> v[4];
	rep(i, n) {
		cin >> x[i] >> y[i];
		rep(j, 4) {
			ll a = x[i];
			ll b = y[i];
			if (j & 1)a *= -1;
			if (j & 2)b *= -1;
			v[j].push_back(a+b);
		}
	}
	rep(j, 4)sort(all(v[j]));
	ll ans = 0;
	rep(j, 4) {
		ll le = v[j].back();
		ll ri = v[3 - j].back();
		ans = max(ans, ri + le);
	}
	cout << ans << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(15);
	init_f();
	//init();
	//expr();
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}


Measured memory_bytes: 21048
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>

#define ipair pair<int,int>
#define rep(n) for(int i=0;i<n;i++)

#define K int('z' - 'a' + 1)

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

int main() {
	int n, i, j;
	int c[K] = {};
	int next_c[K] = {};
	int a = 'a';
	vector<string>s;
	string ans, t;

	cin >> n;

	s.resize(n);

	rep(n) {
		cin >> s[i];
	}
	
	t = s[0];
	rep(t.length()) {
		c[t[i] - a]++;
	}

	rep(n) {
		t = s[i];
		for (j = 0; j < K; j++)
			next_c[j] = 0;
		for (j = 0; j < t.length(); j++) {
			next_c[t[j] - a]++;
		}
		for (j = 0; j < K; j++) {
			c[j] = c[j] > next_c[j] ? next_c[j] : c[j];
		}
	}

	ans = "";

	rep(K) {
		for (j = 0; j < c[i]; j++) {
			ans += char(a + i);
		}
	}

	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**5)
win_hand = {k:v for k, v in zip("r s p".split(), "p r s".split())}


def solve(pt_dict, pred, cur, prev, memo):
  if cur == len(pred):
    return 0
  elif (cur, prev) in memo:
    return memo[(cur, prev)]
  else:
    tmp = 0
    for hand in "r s p".split():
      if prev == hand:
        continue
      else:
        pt = 0
        if hand == win_hand[pred[cur]]:
          pt = pt_dict[hand]
        tmp = max(tmp, pt+solve(pt_dict, pred, cur+1, hand, memo))
    memo[(cur, prev)] = tmp
    return tmp
    
N, K = map(int, input().split())
R, S, P = map(int, input().split())
pt_dict = {}
pt_dict["r"] = R
pt_dict["s"] = S
pt_dict["p"] = P
T = list(input())
k = 0
ans = 0
while k < K:
  ans += solve(pt_dict, T[k::K], 0, "", {})
  k += 1
print(ans)

Measured memory_bytes: 139728
import java.io.*;
import java.util.Arrays;
import java.util.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		Deque<Integer> stack = new ArrayDeque<Integer>();
		for (int i = 0; i<n ; i++ ) {
			String[] str = (br.readLine()).split(" ");
			if (str[0].equals("deleteFirst")) {
				stack.pollFirst();
			}else if(str[0].equals("deleteLast")){
				stack.pollLast();
			}else{
				int a = Integer.parseInt(str[1]);
				if (str[0].equals("insert")) {
					stack.addFirst(a);
				}else{
					stack.remove(a);
				}
			}
		}
		boolean judge = true;
		int k = 0;
		while(judge){
			try{
				int b = stack.pollFirst();
				if (k == 0) {
					System.out.print(b);
				}else{
					System.out.print(" " + b );
				}
				k++;
			}catch (NullPointerException e){
				judge = false;
				System.out.println("");
			}
		}
	}
}

Measured memory_bytes: 192432
# Wrote in 2020-03-01 08:20:36 by reetok
require 'time'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n,datatype=:to_i)
  t = []
  n.times do
    t.push(eval("gets.chomp.#{datatype.to_s}"))
  end
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
#---------------

array = []
loop do
  a = inp[0]
  if a==0
    break
  else
    array.push(a)
  end
end

i = 1
array.each do |n|
  puts "Case #{i}: #{n}"
  i+=1
end


Measured memory_bytes: 7836
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define nn '\n'
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int a,b,c,d,e,k; cin >> a >> b >> c >> d >> e >> k;
    if(max({a,b,c,d,e})-min({a,b,c,d,e})>k){out(":(");}
    else out("Yay!");

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cmath>
#include <cassert>
#define SIZE 100005

using namespace std;
typedef long long int ll;
typedef pair <ll,int> P;

ll B[SIZE],L[SIZE],U[SIZE];
P pos[SIZE];

int main()
{
	int n;
	ll X;
	scanf("%d %lld",&n,&X);
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		scanf("%lld %lld %lld",&B[i],&L[i],&U[i]);
		pos[i]=P((X-B[i])*U[i]+B[i]*L[i],i);
		sum-=B[i]*L[i];
	}
	sort(pos,pos+n);
	ll ret=0;
	int last=0;
	for(int i=n-1;i>=0;i--)
	{
		P p=pos[i];
		if(sum+p.first>=0)
		{
			ret+=(ll) (n-i-1)*(ll) X;
			last=i+1;
			break;
		}
		sum+=p.first;
	}
  // cout<<ret<<" "<<last<<endl;
	ll mn=X;
	sum=-sum;
  // cout<<sum<<endl;
	for(int i=0;i<last;i++)
	{
		int v=pos[i].second;
		mn=min(mn,(sum+L[v]-1)/L[v]);
		ll nsum=sum+B[v]*(U[v]-L[v]);
		mn=min(mn,(nsum+U[v]-1)/U[v]);
	}
	for(int i=last;i<n;i++)
	{
		int v=pos[i].second;
		ll nsum=sum+pos[i].first-pos[last-1].first;
		mn=min(mn,(nsum+L[v]-1)/L[v]);
		ll nsum2=nsum+B[v]*(U[v]-L[v]);
		mn=min(mn,(nsum2+U[v]-1)/U[v]);
	}
	printf("%lld\n",ret+mn);
	return 0;
}


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

int main(){
    long N,H,W,count=0;
    cin >> N >> H >> W;
    long A,B;
    for(int i=0;i<N;i++){
        cin >> A >> B;
        if(A>=H && B>=W){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e5;
const ll INF=1e18;
int n;
ll a[MAX_N];
int main(){
	cin>>n;
	REP(i,n){
		cin>>a[i];
	}
	ll ans=INF;
	REP(f,2){
		bool flg=f;
		ll tem=0;
		ll sm=0;
		REP(i,n){
			sm+=a[i];
			if (flg){
				tem+=max(0ll,-sm+1);
				sm+=max(0ll,-sm+1);
			}else{
				tem+=max(0ll,sm+1);
				sm-=max(0ll,sm+1);
			}
			flg=!flg;
		}
		ans=min(ans,tem);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
k = int(input())
x = list(map(int, input().split(' ')))
a = 0

for i in range(n):
	if abs(x[i]-k) < x[i]:
		a += abs(x[i]-k) * 2
	else:
		a += x[i] * 2
print(a)

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

int main() {
  int a, b;
  cin >> a >> b;
  
  if ( ( a * b ) % 2 == 0) {
    cout << "Even" << endl;
  } 
  
  else {
    cout << "Odd" << endl;
  }
}

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

using namespace std;

typedef long long ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string str;
  cin >> str;
  int K; cin >> K;
  priority_queue<string> PQ;
  set<string> added;
  string fstr{str[0]};
  added.insert(fstr);
  PQ.push(fstr);
  for(int i=0;i<str.size();i++){
    for(int j=1;j<=5;j++){
      // cout << i << " " << j << endl;
      if(i + j - 1 >= str.size()) break;
      string sub = str.substr(i, j);
      if(PQ.size() == 5 && sub >= PQ.top()) continue;
      if(added.find(sub) == added.end()){
        if(PQ.size() >= 5) PQ.pop();
        PQ.push(sub);
        added.insert(sub);
      }
    }
  }
  string ans;
  int PQsize = PQ.size();
  for(int i=1;i<=PQsize - K + 1;i++){
    // cout << PQ.top() << endl;
    ans = PQ.top(); PQ.pop();
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
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 ll MOD = 1e9+7;

int main(){
    ll r, D, x;
    cin >> r >> D >> x;

    for(int i = 0; i < 10; i++){
        x = r*x - D;
        cout << x << 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 n;
    cin >> n;
    long H[n];
    for(int i=0;i<n;i++) cin >>H[i];
    int ans=0,c=0;
    for(int i=1;i<n;i++){
        if(H[i] <= H[i-1]){
            c++;
        } 
        else c = 0;
        ans = max(ans,c);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    int k = Integer.parseInt(sc.next());
    pw.println(Integer.toString(n, k).length());
  }
}


Measured memory_bytes: 22356
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] a=new int[n];
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
    }
    NavigableMap<Integer,Integer> mp=new TreeMap<>();
    for(int i=0;i<n;i++){
      Integer k=mp.lowerKey(a[i]);
//      System.out.println(k);
      if(k!=null){
        if(mp.get(k)==1){
          mp.remove(k);
        }else{
          mp.put(k,mp.get(k)-1);
        }
      }
      mp.put(a[i],mp.getOrDefault(a[i],0)+1);
    }
    int ans=0;
    for(Map.Entry<Integer,Integer> me:mp.entrySet()){
      ans+=me.getValue();
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 56136
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;

inline int read()
{
	int X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}

int n;
int h[N];
int dp[N];

int main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	n=read();

	for(int i=1;i<=n;++i){
		h[i]=read();
	}
	dp[2]=abs(h[2]-h[1]);
	for(int i=3;i<=n;++i){
		dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
	}

	printf("%d\n",dp[n]);

    return 0;
}

Measured memory_bytes: 4520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using Graph = vector<vector<int>>;
const int INF = 10000000;
#define mod 1000000007

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
bool palin(int N){//Nが回文数かどうか
    string S = to_string(N);
    int M = (S.size()-1)/2 + 1;
    int n = S.size();
    bool flag = true;

    for(int i = M;i<n;i++){
        if(S[i] != S[n-i-1]) flag = false;
    }
   return flag;
}
/*まずゴールに辿り着けるかを探索　ゴールまでの距離を求める
最初の白マスの個数ー（距離＋１）が答え
たどり着けない場合、-1を出力
*/

ll factorial(ll n){
    ll i = 1;
    ll ans = 1;
    while(i<=n){
        ans = (i*ans)%mod;
        i++;
    }
    return ans;
}
 
ll calc(ll a,ll b ,ll p){
    if(b == 0){
        return 1;
    }
    else if(b %2 == 0){
        ll d = calc(a,b/2,p);
        return ((d%p)*(d%p))%p;
    }
    else{
        return ((a%p)*calc(a,b-1,p))%p;
    }
}
int main() {
    ll X,Y;
    cin >> X >> Y;


    if((2*Y-X)%3 != 0 || (2*X-Y)%3 != 0) cout << 0 << endl;
    else{
        ll n = (2*Y-X)/3;
        ll m = (2*X-Y)/3;
      if(n < 0 || m <0) cout << 0 << endl;
      else{
        ll ans = (((factorial(n+m)*calc(factorial(n),mod-2,mod)/*nの逆元*/)%mod)*calc(factorial(m),mod-2,mod)/*mの逆元*/)%mod;
    cout << ans << endl;
      }
    }
  
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	final static int MOD = 1000000007;
	
	public static void main(String[] args) {
		MyScanner in = new MyScanner();
//		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		String s = in.next();
//		int b = in.nextInt();
//		System.out.println(b);
		
		if (a>=3200) {
			System.out.println(s);
		} else {
			System.out.println("red");
		}
		
	}
	
	static class MyScanner {
		static Scanner sc = new Scanner(System.in);
		
		String next() {
			return sc.next();
		}
		
		String nextLine() {
			return sc.nextLine();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextInt();
			}
			return array;
		}
		
		double[] nextDoubleArray(int n) {
			double[] array = new double[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextDouble();
			}
			return array;
		}
		
		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}
			return array;
		}
		
		String[] nextLineArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLine();
			}
			return array;
		}
		
		int[][] nextIntMatrix(int n, int m) {
			int[][] matrix = new int[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					matrix[i][j] = nextInt();
				}
			}
			return matrix;
		}
		
		double[][] nextDoubleMatrix(int n, int m) {
			double[][] matrix = new double[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					matrix[i][j] = nextDouble();
				}
			}
			return matrix;
		}
		
		long[][] nextLongMatrix(int n, int m) {
			long[][] matrix = new long[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					matrix[i][j] = nextLong();
				}
			}
			return matrix;
		}
	}
}

Measured memory_bytes: 21716
function main(input) {
   input = input.trim();
  const a = input.split("");
 a.sort(function(a,b){
       if( a < b ) return -1;
       if( a > b ) return 1;
       return 0;
    });   
  const ans = ['a', 'b', 'c'];
 console.log(JSON.stringify(a) == JSON.stringify(ans)?"Yes":"No");

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

int n,a,b;

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

	cin>>n>>a>>b;
	if((a-b)&1) cout<<"Borys"<<endl;
	else cout<<"Alice"<<endl;

	return 0;
}


Measured memory_bytes: 256
import bisect
N=int(input())
L=list(map(int, input().split()))
ans=0
L_LENGTH=len(L)
L=sorted(L)
for i in range(L_LENGTH-2):
    for j in range(i+1, L_LENGTH-1):
        a=L[i]+L[j]
        idx=bisect.bisect_left(L, a)
        ans+=max(0, idx-j-1)
print(ans)


Measured memory_bytes: 43500
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)

int main() {
	string s2;
	cin >> s2;
	bool n=false, s=false, e=false, w=false;
	rep(i, s2.size()) {
		if (s2[i] == 'N')n = true;
		else if (s2[i] == 'S') s=true;
		else if (s2[i] == 'E') e=true;
		else w=true;
	}

	if (!(n ^ s) && !(e ^ w)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}



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

#define ll long long
#define rep(i,N) for(ll i=0; i<N; i++)
const int mx = 2e5;

int main(void){
  ll K,A,B;
  cin >> K;
  cin >> A>>B;
  
  ll N;
  N=A/K;
  N = N*K;
  bool OK = false;
  while(N<=B){
    if(B>=N && N>=A){
      OK = true;
      break;
    }
    N+=K;
  }
  
  if(OK){
    cout << "OK";
  }else{
    cout << "NG";
  }

  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
long long int n,ans=0;
void check(long long x) {
	long long nn=n;
	while(nn%x==0) nn/=x;
	if(nn%x==1) ans++;
}
int main(){
    
    cin>>n;
    for(long long i=1;i*i<=n;i++){
    	if((n-1)%i==0) {
			if(i>1) ans++;
			if(i*i!=n-1) ans++;
		}
	}
	for(long long i=1;i*i<=n;i++){
	
		if(n%i==0) {
			if(i>1) check(i);
			if(i*i!=n) check(n/i);
		}
	}
	cout<<ans<<endl;
	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    string s; cin >> s;
    long long count = 0;
    map<char,int> mp;
    for(int i=0;i<n;++i){
        mp[s[i]]++;
    }
    for(int i=0;i<n-1;++i){
        char a;
        a = s[i];
        for(int j=i+1;j<n;++j){
            if(s[j] == a) continue;
            else{
                char b = s[j];
                if(2*j-i>n-1) continue;
                if(s[2*j-i]!=a && s[2*j-i]!=b){
                    count++;
                }
            }
        }
    }
    long long ans = (long long)mp['R'] * mp['G'] * mp['B'] - count;
    if(ans < 0) ans = 0;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n,m;
  while(cin>>n>>m,n){
    vector< vector<int> > B(n,vector<int>(m));
    {
      char c;
      for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
          cin>>c,B[i][j]=c-'0';
    }
    if(n<=20){
      using BS = bitset<512>;
      vector<BS> bb(n,0);
      for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
          if(B[i][j]) bb[i].flip(j);

      int ans=0;
      int sz=1<<n;
      for(int bit=0;bit<sz;bit++){
        BS st(0);
        int cnt=0;
        for(int i=0;i<n;i++){
          if((~bit>>i)&1) continue;
          st^=bb[i];
          cnt++;
        }
        if(st==BS(0)) chmax(ans,cnt);
      }
      cout<<ans<<endl;
    }else{
      int sz=1<<m;
      vector<int> dp(sz,-n*2);
      dp[0]=0;
      for(int i=0;i<n;i++){
        int val=0;
        for(int j=0;j<m;j++)
          val|=B[i][j]<<j;
        vector<int> nx(sz,-n*2);
        for(int bit=0;bit<sz;bit++){
          chmax(nx[bit],dp[bit]);
          chmax(nx[bit^val],dp[bit]+1);
        }
        swap(dp,nx);
      }
      cout<<dp[0]<<endl;
    }
  }

  return 0;
}



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

typedef long long int ll;
typedef double d;

#define tt int t; cin>>t; while(t--)
#define lo(i, a, b) for(int i=a; i<b; i++)
#define rlo(i, a) for(int i=a; i>0; i--)

#define be(a) a.begin(),a.end()
#define sz(x) x.size()

#define nl cout<<"\n";
#define sp cout<<" ";

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

int main()
{
    su;
    string s,t,u,u1,s1,t1;
    cin>>u;
    int n=sz(u);
    u1=u;
    reverse(be(u));
    if(u==u1)
    {
        lo(i,0,(n-1)/2)
        s+=u1[i];
        s1=s;
        reverse(be(s));
        if(s==s1)
        {
            lo(i,((n+3)/2)-1,n)
            t+=u1[i];
            t1=t;
            reverse(be(t));
            if(t==t1)
                cout<<"Yes";
            else
                cout<<"No";
        }
        else
            cout<<"No";
    }
    else
        cout<<"No";
    nl;
    return 0;
}


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

int main(){
    ll x,a,b,f;
    cin>>x;
    f=1;
    for(a=0;(a<=1e4 && f==1);a++){
        for(b=0;b<=1e4;b++){
            if ((pow(a,5)-pow(b,5))==x){
                cout<<a<<" "<<b<<endl;
                f=0;
            }else if((pow(a,5)+pow(b,5))==x){
                cout<<a<<" "<<-b<<endl;
                f=0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 4128
#include <iostream>
#include <math.h>
using namespace std;

int main(int argc, char *argv[]) {
    int n;
    int h,p,q,m,s;
    int c;
    cin >> n;
    for(int i=1;i<=n;i++){
        c=0;
        for(int j=1;j*j<i;j++){
            for(int k=1;k*k<i-j*j;k++){
                for(int l=1;l*l<i-j*j-k*k;l++){
                    if(l*l+k*k+j*j+l*j+l*k+j*k==i) c++;
                    if(l*l+k*k+j*j+l*j+l*k+j*k>i) break;
                }
            }
        }
        cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;

namespace D_After
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int[] a = new int[input.Length + 1];
            for (int i = 1; i < a.Length; i++)
                a[i] = a[i - 1] ^ (1 << (input[i - 1] - 'a'));
            int[] opt = new int[input.Length + 1];
            Dictionary<int, int> dp = new Dictionary<int, int>();            
            for (int i = 1; i <= input.Length; i++)
            {
                if (!dp.ContainsKey(a[i - 1]))
                    dp.Add(a[i - 1], int.MaxValue);
                dp[a[i - 1]] = dp[a[i - 1]] <= opt[i - 1] ? dp[a[i - 1]] : opt[i - 1];
                opt[i] = Enumerable.Range(-1, 27).Select(x => x < 0 ? 0 : 1 << x).Select(x => dp.ContainsKey(a[i] ^ x) ? dp[a[i] ^ x] : int.MaxValue).Min() + 1;
            }

            Console.WriteLine(opt[opt.Length - 1]);
# if DEBUG
            Console.ReadKey();
#endif
        }
    }
}


Measured memory_bytes: 29716
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

vector<int> as;
vector<int> lms;
vector<int> rms;

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

    as.resize(N + 1, 0);
    for (int i = 0; i < N; i++) {
        cin >> as[i + 1];
    }

    lms.resize(N + 1, 0);
    for (int i = 0; i < N; i++) {
        lms[i + 1] = max(lms[i], as[i + 1]);
    }

    rms.resize(N + 1, 0);
    for (int i = 0; i < N; i++) {
        rms[i + 1] = max(rms[i], as[N - i]);
    }

    for (int i = 1; i <= N; i++) {
        cout << max(lms[i - 1], rms[N - i]) << endl;
    }

    return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int n,m;
ll ans;
int wide[1500001],hight[1500001];
int w[1505],h[1505];

void enumerate_hight(){
  int sum;
  for(int i=0;i<n;i++){
    sum=0;
    for(int j=i;j<n;j++){
      sum+=h[j];
      hight[sum]++;
    }
  }
}

void enumerate_wide(){
  int sum;
  for(int i=0;i<m;i++){
    sum=0;
    for(int j=i;j<m;j++){
      sum+=w[j];
      wide[sum]++;
    }
  }
}

void solve(){
  ll max_w=0,max_h=0,maxi;
  ans=0;
  for(int i=0;i<n;i++){scanf("%d",&h[i]);max_h+=h[i];}
  enumerate_hight();
  for(int i=0;i<m;i++){scanf("%d",&w[i]);max_w+=w[i];}
  enumerate_wide();
  maxi=max(max_w,max_h);
  rep(i,maxi+1){ans+=wide[i]*hight[i];wide[i]=hight[i]=0;}
  cout<<ans<<endl;
}

int main(){
  while(scanf("%d%d",&n,&m)){
    if(n==0&&m==0)break;
    solve();
  }
}

Measured memory_bytes: 7176
package main

import (
	"fmt"
	"math"
)

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n int
	fmt.Scan(&n)

	b := make([]int, n)
	for i := range make([]struct{}, n) {
		fmt.Scan(&b[i])
		if i != 0 {
			b[i] += b[i-1]
		}
	}

	ans := math.MaxInt64
	for i := range make([]struct{}, n-1) {
		ans = min(ans, abs(b[n-1]-2*b[i]))
	}

	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <iostream>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

#define l first
#define r second
#define int long long

int n;
int a[500000];
int b[500000];

set<pair<int, int>, greater<pair<int, int> > > ss;

signed main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i], ss.insert({b[i], i});
    int ans = 0;
    for (;;)
    {
        if (ss.size() == 0)
        {
            break;
        }
        pair<int, int> p = *ss.begin();
        ss.erase(ss.begin());
        int s = b[(n + p.second + 1) % n] + b[(n + p.second - 1) % n];
        if (p.first == a[p.second])
        {
            continue;
        }
        if (p.first - s < a[p.second])
        {
            cout << -1;
            return 0;
        }
        else
        {
            int kek = 0;
            if (ss.size() == 0)
                kek = a[p.second];
            else
                kek = min(a[p.second], (*ss.begin()).first);
            ans += (p.first - kek) / s;
            int d = ((p.first - kek) / s) * s;
            b[p.second] -= d;
            p.first -= d;
            ss.insert(p);
        }
    }
    cout << ans;
}

Measured memory_bytes: 18432
#include<iostream>
using namespace std;
int main(){
  int a,b,k,kc=0,p;
  cin >> a >> b>>k;
  while(k!=kc){
    cout << a+kc << endl;
    kc++;
    if(a+kc>=b)break;
  }
  p=kc;
  kc--;
  while(kc>=0){
    if(p+a<=b-kc) cout << b-kc <<endl;
    kc--;
    if(b-kc<=a)break;
  }
}


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

int main()
{
    int n, height{}, count[2]{};
    char s[128]{};
    scanf("%d%s", &n, s);
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '(') height++;
        else height--;
        if (height < 0)
        {
            count[0]++;
            height++;
        }
    }
    count[1] = height;
    for (int i = 0; i < count[0]; i++)
        printf("(");
    printf(s);
    for (int i = 0; i < count[1]; i++)
        printf(")");
    printf("\n");

    return 0;
}

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

typedef long long int ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vll> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpl;
typedef unordered_set<ll> usl;
typedef set<ll> sl;
typedef unordered_map<ll, ll> uml;
typedef map<ll, ll> ml;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

#define all(v) v.begin() , v.end()
#define ceil(a, b) (a + b - 1) / b
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll inf = 1e9 + 7;
const double pie = 3.14159265358979323846;
const char nl = '\n';
const char spc = ' ';

template<typename Type>
istream &operator>>(istream &in, vector<Type> &v)
{
    ll n = v.size();
    for (int i = 1; i < n; i++)
        in >> v[i];
    return in;
}

template<typename Type>
ostream &operator<<(ostream &out, vector<Type> &v)
{
    for (auto value : v)
        out << value << ' ';
    out << nl;
    return out;
}

bool isPrime (ll n)
{
    if (n < 4)
        return true;
    if (n % 2 == 0)
        return false;
    ll i = 3;
    while (i * i <= n)
    {
        if (n % i == 0)
            return false;
        i += 2;
    }
    return true;
}

void solve ()
{
    ll n;
    cin >> n;
    vll a(n + 1);
    cin >> a;
    vll dp(1e5 + 1, 0);
    dp[2] = abs(a[2] - a[1]);
    for (ll i = 3; i <= n; ++i)
        dp[i] = min ((dp[i - 1] + abs(a[i] - a[i - 1])), (dp[i - 2] + abs(a[i] - a[i - 2])));
    cout << dp[n] << nl;
}

int main()
{
    IOS
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll t;
    t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

map<ll, ll> PrimeFactor(ll n) {
    map<ll, ll> res;
    for(ll i = 2; i * i <= n; ++i) {
        while(n % i == 0) {
            ++res[i];
            n /= i;
        }
        if(LLINF / i <= i) { break; }  // オーバーフロー警察
    }
    if(n != 1) { res[n] = 1; }
    return res;
}

int N;

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

    cin >> N;
    auto res = PrimeFactor(N);
    int ans = 0;
    for(auto& p : res) {
        int count = p.second;
        int cand = 0;
        for(int i = 1; i < 100000000; ++i) {
            int tmp = i * (i + 1) / 2;
            if(count >= tmp) {
                cand = i;
            }
            else {
                break;
            }
        }
        ans += cand;
    }
    printf("%lld\n", ans);

    return 0;
}


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

int main(){
  long long *libs;
  libs = new long long[1000000];

  for(long i=0;i<1000000;++i){
    libs[i] = 0;
  }

  for(long long  i = 1;i<1000000;++i){
    for(long long j = 1;j<1000000;++j){
      if(i * j >= 1000000) break;
      libs[i * j] += 1;
    }
  }

  long ans = 0;
  long N;

  cin >> N;
  
  for(long i = 1;i<N;++i){
    ans += libs[i];
  }

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

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

const int N = 2e5 + 10;

int n, win[N],lvl[N];
vi adj[N];

int deep;
void dfs(int u, int p) {
    if (lvl[u] > lvl[deep]) deep = u;
    for (int v : adj[u]) if (v != p) {
        lvl[v] = lvl[u]+1;
        dfs(v,u);
    }
}

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

    win[0] = 0;
    win[1] = 1;
    win[2] = 0;
    for (int d = 3; d < N; d++) win[d] = !win[d-1] || !win[d-2];

    cin >> n;
    forn(_,n-1) {
        int u,v; cin >>u >> v;
        u--; v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    dfs(0,0);
    lvl[deep] = 0; dfs(deep, deep);
    int diam = lvl[deep];
    bool ans = win[diam+1];
    cout << (ans ? "First" : "Second");
    return 0;
}


Measured memory_bytes: 22144
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

char grid[52][52];

bool is_ok(int x, int y){
	int dx[4] = {1, 0, -1, 0};
	int dy[4] = {0, 1, 0, -1};
	for (int i = 0; i < 4; i++){
		if (grid[x+dx[i]][y+dy[i]] == '#') return true;
	}
	return false; 
}

int main(){
	int h, w;
	cin >> h >> w;
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			cin >> grid[i][j];
		}
	}

	for (int i = 1; i <= h; i++){
		for (int j = 1; j<= w; j++){
			if (grid[i][j] == '#'){
				if (!is_ok(i, j)){
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<stdio.h>
#include<string.h>
using namespace std;
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define rep(i,t,n) for(int i=t;i<n;i++)
#define nd "\n"
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>




/*ll power(ll x,ll t){
if(t<=0){
    return 1;
}
ll y=(power(x,t/2));
y=(y*y)%ma;
if(t%2)
    y=(y*x)%ma;
return y;

}*/
/*ll ph[100001];
void E_phi(int n){

ph[0]=0;
ph[1]=1;
for(int i=2;i<=n;i++){
    ph[i]=i;
}
for(int i=2;i<=n;i++){
    if(ph[i]==i){
        for(int j=i;j<=n;j+=){
            ph[j]-=ph[j]/i;
        }
    }
}


}*/
/*string s,t;
vector<int>  z_fun(string s){

int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}*/

/*struct st{
ll sum,pre,suf,ans;
st(){}
st(ll k){
ans=k,pre=k,suf=k,sum=0;
}

};
ll t[4*200001+4];
ll a[200001];
ll lazy[4*200001+4];
ll mx=1e14;



void push(int ind){
int l=2*ind+1,r=2*ind+2;
t[l]+=lazy[ind];
t[r]+=lazy[ind];
lazy[l]+=lazy[ind];
lazy[r]+=lazy[ind];
lazy[ind]=0;

}

void build(int ind,int l,int r){
if(l==r){
    t[ind]=a[l];
return;
}
int mid=(l+r)/2;
build(2*ind+1,l,mid);
build(2*ind+2,mid+1,r);

  t[ind] =min(t[ind*2+1] , t[ind*2+2]);



}
ll query(int ind,int l,int r,int p,int q){

if(l>q || r<p )
    return mx;
    int mid=(l+r)/2;

if(l>=p && r<=q )
    {
      return t[ind];
    }
    push(ind);
ll x=query(2*ind+1,l,mid,p,q);
ll y=query(2*ind+2,mid+1,r,p,q);


return min(x,y);
}

void update(int ind,int l,int r,int p,int q,int val){
if(l>q || r<p )
    return;

if(l>=p && r<=q )
    {
      t[ind]+=val;
      lazy[ind]+=val;
      return;
    }
push(ind);
int mid=(l+r)/2;
    update(2*ind+1,l,mid,p,q,val);
     update(2*ind+2,mid+1,r,p,q,val);
    t[ind]=min(t[2*ind+1],t[2*ind+2]);



}


ll mod(ll a){
if(a>=0)
    return a;
else return -a;
}
*/


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
int n;
cin>>n;
int l[n],r[n];
rep(i,0,n)cin>>l[i]>>r[i];
for(int i=0;i<=n-3;i++){
    int f=1;
    for(int j=0;j<3;j++){
        if(l[i+j]!=r[i+j]){f=0;break;}
    }
    if(f){
        cout<<"Yes"<<endl;
        return 0;
    }
}
cout<<"No"<<endl;


}


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

typedef long long ll;

// 累乗（nが基数、kが指数）
ll pow(int n, int k) {
  ll res = 1;
  for (int i = 0; i < k; i++) {
    res *= n;
  }

  return res;
}

int main() {
  int N, P;
  cin >> N >> P;
  int a[N];
  for (int i = 0; i < N; i++) cin >> a[i];

  // 奇数の袋が存在するかどうか確かめる
  bool flag = false; // 全て偶数の袋と仮定
  for (int i = 0; i < N; i++) {
    if (a[i] & 1) flag = true;
  }

  ll ans = 0;
  if (!flag) {
    if (P == 0) ans = pow(2, N);
  } else {
    ans = pow(2, N - 1);
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
*C, = map(int,input().split())

mod = 10**9+7

C.sort()

ans = 0
for i,c in enumerate(C):
    tmp = (pow(2,N-1-i,mod) + pow(2,max(0,N-2-i),mod)*(N-1-i))%mod
    tmp = (tmp*c)%mod
    tmp = (tmp*pow(2,i,mod))%mod
    ans += tmp
    ans %= mod
ans *= pow(2,N,mod)
ans %= mod
print(ans)

Measured memory_bytes: 25508
#include<cstdio>

int main() {
    int a,b,c;
    int n=0;
    scanf("%d %d %d", &a,&b,&c);
    while(a<=b) {
        if(a>b) break;
        if (c%a==0) n++;
        a++;
    }
    printf("%d\n", n);
}



Measured memory_bytes: 2732