akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int mod=998244353,INF=1e9+7;
const int N=1002020;
int n,gr[N],f[N],x1[N],suf[N];
struct Robot{int x,d;}rb[N];
bool cmp(const Robot &x,const Robot &y){return x.x<y.x;}
struct Fenwick_Tree{
	int c[N];
	int lowbit(int x){return x & (-x);}
	void add(int x,int y){for(;x<=n;x+=lowbit(x))c[x]=max(c[x],y);}
	int ask(int x){int r=0;for(;x;x-=lowbit(x))r=max(r,c[x]);return r;}
}tr;
int read(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		rb[i].x=read(),rb[i].d=read();
	sort(rb+1,rb+n+1,cmp);
//	for(int i=1;i<=n;i++)cout<<rb[i].x<<"("<<rb[i].d<<") ";cout<<endl;
	for(int i=1;i<=n;i++)x1[i]=rb[i].x;
	x1[n+1]=INF;
	for(int i=n;i>=1;i--){
		int th=lower_bound(x1+1,x1+n+2,rb[i].x+rb[i].d)-x1; --th;
		gr[i]=max(i,tr.ask(th)); tr.add(i,gr[i]);
	}
	f[n+1]=1;
	for(int i=n;i>=1;i--)
		f[i]=(f[i+1]+f[gr[i]+1])%mod;
	cout<<f[1]<<endl;
	return 0;
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define N 10000
vector<int> par(N);
vector<int> ranks(N);

void init(int n)
{
  int i;
  rep(i,n)
  {
    par[i]=i;
    ranks[i]=0;
  }
}

int find(int x)
{
  if(par[x]==x)return x;
  else return par[x] = find(par[x]);
}

void unite(int x, int y)
{
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(ranks[x]<ranks[y])par[x]=y;
  else
  {
    par[y]=x;
    if(ranks[x]==ranks[y])ranks[x]++;
  }
}

bool same(int x, int y)
{
  return find(x) == find(y);
}

double dist(double x1,double x2,double y1,double y2,double z1,double z2)
{
  return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
}

int main()
{
  int n;cin>>n;
  while(n!=0)
  {
    vector<double> x(n);
    vector<double> y(n);
    vector<double> z(n);
    vector<double> r(n);
    int i,j;
    rep(i,n)cin>>x[i]>>y[i]>>z[i]>>r[i];
    vector<int> a(n*n);
    vector<int> b(n*n);
    vector<double> cost(n*n);
    rep(i,n)rep(j,n)
    {
      a[i*n+j]=i;
      b[i*n+j]=j;
      double dis=dist(x[i],x[j],y[i],y[j],z[i],z[j]);
      if(dis<=r[i]+r[j])cost[i*n+j]=0.0;
      else cost[i*n+j]=dis-(r[i]+r[j]);
    }
    init(n);
    vector<pair<double,int>> p(n*n);
    rep(i,n*n)p[i]=make_pair(cost[i],i);
    sort(all(p));
    double ans=0.0;
    rep(i,n*n)
    {
      int ind=p[i].second;
      if(!same(a[ind],b[ind]))
      {
        unite(a[ind],b[ind]);
        ans+=p[i].first;
      }
    }
    cout<<fixed<<setprecision(3)<<ans<<endl;
    cin>>n;
  }
}




Measured memory_bytes: 3496
def knapsack_dp(n,w,wts,val):
    dp=[[0]*(w+1) for i in range(n+1)]

    for i in range(n+1):
        for j in range(w+1):
            if i==0 or j==0:
                dp[i][j]=0
            elif wts[i-1]<=j:
                dp[i][j]=max(dp[i-1][j],val[i-1]+dp[i-1][j-wts[i-1]])
            else:
                dp[i][j]=dp[i-1][j]

    return dp[n][w]


n,w=map(int,input().split())
wts,vals=[],[]
for i in range(n):
    a,b=map(int,input().split())
    wts.append(a)
    vals.append(b)

print(knapsack_dp(n,w,wts,vals))


Measured memory_bytes: 119916
h,w,k = map(int, input().split())
#2dim-list
def toint(c):
  if c=="#":
    return 1
  elif c==".":
    return 0

s = [[si for si in input()] for i in range(h)]

for i in range(h):
  for j in range(w):
    s[i][j]=toint(s[i][j])
#print(s)
############################################
def start(s,ret):
  count=1
  for i in range(h):
    for j in range(w):
      if s[i][j]==1:
        ret[i][j]=count
        count+=1
  return ret
  
def colorL(ret,ki,i,j):
  if 0<j:
    if ret[i][j-1]==0:
      ret[i][j-1]=ki
      ret = colorL(ret,ki,i,j-1)
  return ret

def colorR(ret,ki,i,j):
  if j<w-1:
    if ret[i][j+1]==0:
      ret[i][j+1]=ki
      ret = colorR(ret,ki,i,j+1)
  return ret
  
def copyUP(ret, i):
  if 0<i:
    if ret[i-1][0]==0:
      ret[i-1]=ret[i]
      ret = copyUP(ret, i-1)
  return ret

def copyDOWN(ret, i):
  if i<h-1:
    if ret[i+1][0]==0:
      ret[i+1]=ret[i]
      ret = copyDOWN(ret, i+1)
  return ret
############################################
ret = [[0]*w for i in range(h)]
#print(ret)
ret = start(s,ret)


for i in range(h):
  for j in range(w):
    if ret[i][j]!=0:
      ret = colorL(ret,ret[i][j],i,j)
      ret = colorR(ret,ret[i][j],i,j)



for i in range(h):
  if ret[i][0]!=0:
    copyUP(ret, i)
    copyDOWN(ret, i)
#print(ret)

for i in range(h):
  tmp=" ".join(map(str, ret[i]))
  print(tmp)

Measured memory_bytes: 7920
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    int N;
    cin >> N;
    vector<pair<string,pair<int,int>>> p(N);
    for(int i=0; i<N; i++){
        cin >> p[i].first >> p[i].second.first;
        p[i].second.first *= -1;
        p[i].second.second = i;
    }
    sort(p.begin(),p.end());
    for(int i=0; i<N; i++){
        cout << p[i].second.second+1 << enld;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    int H, N;
    std::cin >> H >> N;
    std::vector<i64> a(N);
    rep(i, N) std::cin >> a[i];
    i64 as = std::accumulate(a.begin(), a.end(), 0LL);
    if(as >= H) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}

int main() {
    // std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	bool isFour = false;

	vector<char> s(n);
	for (int i = 0; i < n; i++)
	{
		cin >> s.at(i);
		if (s.at(i) == 'Y')
		{
			isFour = true;
		}
	}

	if (isFour)
	{
		cout << "Four" << endl;
	}
	else
	{
		cout << "Three" << endl;
	}
}


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

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[ ";
    for(auto a : v)
        os << a << " ";
    os << "]";
    return os;
}

int main() {
    cout << fixed << setprecision(0);
    int N;
    cin >> N;
    vector<int> A(N);
    for(auto &a : A)
        cin >> a;

    int64_t ans = 0;
    int sh = A[0];
    for(int i = 1; i < N; i++) {
        if(A[i] < sh) {
            ans += sh - A[i];
        }
        sh = max(sh, A[i]);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

const int P = 998244353, N = 1000001;

int add(int a, int b) { int r = a + b; return r < P ? r : r - P; }
int sub(int a, int b) { int r = a - b; return r < 0 ? r + P : r; }
int mul(long long a, long long b) { return a * b % P; }

int mu[N]; bool ip[N]; vector<int> ps;
void sieve() {
    fill_n(ip, N, 1);
    ip[1] = 0; mu[1] = 1;
    for (int i = 2; i != N; ++i) {
        if (ip[i]) { ps.push_back(i); mu[i] = P - 1; }
        for (int j : ps) {
            if (i * j >= N) break;
            ip[i * j] = 0;
            if (i % j) mu[i * j] = sub(0, mu[i]);
            else {
                mu[i * j] = 0;
                break;
            }
        }
    }
}

vector<int> ds[N];
int a[N], c[N];

int main(void) {
    int n; scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i)
        c[a[i]]++;

    sieve();

    for (int i = 1; i != N; ++i)
        for (int j = i; j < N; j += i)
            ds[j].push_back(i);

    int res = 0;
    for (int T = 1; T != N; ++T) {
        int u = 0;
        for (int e : ds[T])
            u = add(u, mul(e, mu[e]));
        int v = 0;
        for (int x = 1; x <= (N - 1) / T; ++x)
            v = add(v, mul(x, c[x * T]));
        res = add(res, mul(T, mul(u, mul(v, v))));
    }

    int ans = res;

    for (int i = 1; i <= n; ++i)
        ans = sub(ans, a[i]);

    ans = mul(ans, (P + 1) / 2);

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 127736
#include <iostream>
#include <cstdio>
#include <math.h>

using namespace std;

typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const int MOD = 1000000007;
const int INF = INT_MAX;



int main(int argc, char const *argv[])
{
    char b;
    cin >> b;

    char a;
    if (b == 'A') a = 'T';
    if (b == 'T') a = 'A';
    if (b == 'C') a = 'G';
    if (b == 'G') a = 'C';


    cout << a << endl;



    return 0;
}




//              g++ -std=c++1z  

Measured memory_bytes: 888
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    const int MAX_N = 500;
    int N, M, Q;
    cin >> N >> M >> Q;
    int L, R, X[MAX_N + 1][MAX_N + 1] = {};
    REP(i, M) {
        cin >> L >> R;
        X[L][R]++;
    }
    int C[MAX_N + 1][MAX_N + 1] = {};
    FOR(i, 1, N + 1, 1) {
        FOR(j, 1, N + 1, 1) {
            C[i][j] = C[i][j - 1] + X[i][j];
        }
    }
    int p, q;
    REP(i, Q) {
        int res = 0;
        cin >> p >> q;
        FOR(j, p, q + 1, 1) {
            res += C[j][q] - C[j][p - 1];
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <cstring>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
    string s;
    int n;
    cin >> s >> n;
    
    string a, d;
    int b, c;
    for(int i = 0; i < n; i++){
        cin >> a >> b >> c;
        int l = c - b + 1 ;
        if(a == "replace"){
            cin >> d;
            s.replace(b, l, d);
        }else if(a == "reverse"){
            string z = s.substr(b, l);
            reverse(z.begin(), z.end());
            s.replace(b, l, z);
        }else if(a == "print"){
            cout << s.substr(b, l) << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
const double EPS=1e-2;
int main(){
	int n;
	cin >> n;
    int l=n/1.08, u=l+1;
    if(floor(l*1.08)==n){
        cout << l << endl;
    }else if(floor(u*1.08)==n){
        cout << u << endl;
    }else{
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define endl "\n"
#define all(x) (x).begin(),(x).end()
const int MOD = 1e9+7;
const int mxN = 2e5+3;

void solve(){
	int n,k;
	cin >> n >> k;
	int p[n];
	for(int i = 0; i < n; ++i)cin >> p[i];
	sort(p , p+n);
	int ans = 0;
	for(int i = 0; i < k; ++i){
		ans += p[i];
	}
	cout << ans << endl;
}

int32_t main(){
	IO;
	
	int nT = 1;
	//cin >> nT;
	for(int i = 1; i <= nT; ++i)
		solve();
	return 0;
}


Measured memory_bytes: 3652
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

void solve() {
}

string a, b, c;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif

        cin >> a >> b >> c;
        char next = 'a';
        int ia = 0, ib = 0, ic = 0;
        while (true) {
            if (next == 'a') {
                if (ia == a.size()) {
                    cout << "A" << endl;
                    return 0;
                }

                next = a[ia];
                ia++;
            } else if (next == 'b') {
                if (ib == b.size()) {
                    cout << "B" << endl;
                    return 0;
                }

                next = b[ib];
                ib++;
            } else {
                if (ic == c.size()) {
                    cout << "C" << endl;
                    return 0;
                }

                next = c[ic];
                ic++;
            }
        }
        solve();

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
s=input()
k=int(input())
fi=0
se=0
t=s+s
n=len(s)
now=1
for i in range(1,n):
  if s[i]==s[i-1]:
    now+=1
  else:
    fi+=now//2
    now=1
fi+=now//2
now=1
for i in range(1,n*2):
  if t[i]==t[i-1]:
    now+=1
  else:
    se+=now//2
    now=1
se+=now//2
ans=(se-fi)*(k-1)+fi
#print(se,fi)
ok=True
for i in range(n-1):
  if s[i]!=s[i+1]:
    ok=False
    break
if ok:
  ans=n*k//2
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
typedef long long int ll;
using namespace std;


ll n, m;
vector<ll> h, a, b;
vector<vector<ll>> adj;

int main(){
  cin >> n >> m;
  h = vector<ll>(n);
  for(ll i=0;i<n;i++) cin >> h[i];
  a = vector<ll>(m);
  b = vector<ll>(m);
  adj = vector<vector<ll>>(n);
  for(ll i=0;i<m;i++){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    adj[a[i]].pb(b[i]);
    adj[b[i]].pb(a[i]);
  }
  ll ans = 0;
  for(ll i=0;i<n;i++){
    bool good = true;
    for(auto j: adj[i]){
      if (h[i] <= h[j]) good = false;
    }
    if (good) ans++;    
  }  
  cout << ans << endl;
  return 0;
}
  

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

int main()
{
     string  s,t,a;
     cin>>s;
     cin>>t;

    a = t.substr(0,s.length());

  if(s==a)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;

return 0;
}

Measured memory_bytes: 3580
#pragma GCC optimize("Ofast,O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;

#define endl '\n'
#define hoise cerr<<"hoise - "<<__LINE__<<"\n";
#define tham getchar();
#define FASTIO ios::sync_with_stdio(false);cin.tie(nullptr);

using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;
using vl = vector <ll>;

const int MXN = (int)2e5+6;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int INF = 1e9;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(ll N, ll pos){return (bool)(N & (1LL<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }


template <typename T> using orderedSet = tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using orderedSet1 = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*--------------------------------------------------------------------------------------------------------------------------*/




int main(){
	FASTIO
	ll x;
	cin >> x;
	ll initial = 100;
	
	for (int i = 1; ; ++i) {
		initial = initial + initial / 100;
		if (initial >= x) {
			cout << i << endl;
			return 0;
		}
	}
	
    return 0;
}

/*

*/


Measured memory_bytes: 3648
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

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

    vector<int> vprime;
    vprime.push_back(2);
    vprime.push_back(3);
    vprime.push_back(5);
    vprime.push_back(7);
    vprime.push_back(11);
    vprime.push_back(13);
    vprime.push_back(17);
    vprime.push_back(19);
    vprime.push_back(23);
    vprime.push_back(29);
    vprime.push_back(31);
    vprime.push_back(37);
    vprime.push_back(41);
    vprime.push_back(43);
    vprime.push_back(47);

    vector<int> n_prime_factor(vprime.size(), 0);
    for (int i = 0; i < vprime.size(); i++)
    {
        int tmp = vprime[i];
        while (tmp <= N)
        {
            n_prime_factor[i] += (N / tmp);
            tmp = vprime[i] * tmp;
        }
    }

    int ans = 0;
    //(2, 24)
    for (int i = 0; i < vprime.size(); i++)
    {
        for (int j = 0; j < vprime.size(); j++)
        {
            if (i != j && n_prime_factor[i] >= 2 && n_prime_factor[j] >= 24)
                ans++;
        }
    }

    //(4, 14)
    for (int i = 0; i < vprime.size(); i++)
    {
        for (int j = 0; j < vprime.size(); j++)
        {
            if (i != j && n_prime_factor[i] >= 4 && n_prime_factor[j] >= 14)
                ans++;
        }
    }

    //4,4,2
    for (int i = 0; i < vprime.size(); i++)
    {
        for (int j = i + 1; j < vprime.size(); j++)
        {
            for (int l = 0; l < vprime.size(); l++)
            {
                if (i != j && i != l && j != l)
                {
                    if (n_prime_factor[i] >= 4 && n_prime_factor[j] >= 4 && n_prime_factor[l] >= 2)
                    {
                        ans++;
                    }
                }
            }
        }
    }

    //74

    for (int i = 0; i < vprime.size(); i++)
    {
        if (n_prime_factor[i] >= 74)
        {
            ans++;
        }
    }

    cout << ans << endl;
}

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

typedef long long LL;
std::priority_queue<LL> L;
std::priority_queue<LL, std::vector<LL>, std::greater<LL> > R;
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	int n; std::cin >> n;
	const LL INF = 0x3f3f3f3f3f3f3f3fLL;
	L.push(-INF), R.push(INF);
	LL tl = 0, tr = 0, lst = 0, ans = 0;
	for (int i = 1; i <= n; ++i) {
		LL l, r, len; std::cin >> l >> r;
		tl -= lst, tr += len = r - l, lst = len;
		LL pl = L.top() + tl, pr = R.top() + tr;
		if (pl <= r && r <= pr) L.push(r - tl), R.push(r - tr);
		else if (r < pl) {
			L.pop(); L.push(r - tl), L.push(r - tl), R.push(pl - tr);
			ans += pl - r;
		} else {
			R.pop(), R.push(r - tr), R.push(r - tr), L.push(pr - tl);
			ans += r - pr;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 2036
N = int(input())
h = [list(map(int, input().split())) for _ in range(N)]
dp = [[0]*N for _ in range(3)]
for i in range(3):
    dp[i][0] = h[0][i]

for i in range(1, N):
    dp[0][i] = max(dp[1][i-1], dp[2][i-1]) + h[i][0]
    dp[1][i] = max(dp[0][i-1], dp[2][i-1]) + h[i][1]
    dp[2][i] = max(dp[0][i-1], dp[1][i-1]) + h[i][2]

print(max(dp[0][N-1], dp[1][N-1], dp[2][N-1]))

Measured memory_bytes: 65752
import java.util.Scanner;

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

		if (n.contains("a") && n.contains("b") && n.contains("c")) {
			ans = "Yes";
		}

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 23764
// abc136d.cpp : Gathering Children
#include <bits/stdc++.h>
using namespace std;
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)

int main(){
  string S; cin>>S;
  int n = S.length();
  vector<int> ans(n), divpoint, group;

  bool high_low = false; // low
  up(i,0,n,1){
    if(!high_low && S[i]=='R'){ // ↑
      divpoint.push_back(i); // グループの切れ目
      high_low = true; // hi
    }
    else if(high_low && S[i]=='L'){ // ↓
      group.push_back(i); // グループの集合場所（L側）
      high_low = false; // low
    }
  }
  divpoint.push_back(n);

  up(i,0,group.size(),1){
    int gp = group[i], dp = divpoint[i];
    int a = divpoint[i+1] - dp;
    int o = (a%2 && dp%2)? a/2+1: a/2;
    int R, L; if(gp%2){R=a-o; L=o;} else{R=o; L=a-o;}
    ans[gp-1] = R; ans[gp] = L;
  }

  ot(ans[0]); up(i,1,n,1) cout<<" "<<ans[i]; ot("\n");
}

Measured memory_bytes: 1532
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<string> s(N);
  REP(i, N) cin >> s[i];

  int ans = 0;
  REP(k, N){
    bool flag = true;
    REP(i, N) REP(j, N){
      if(s[(i+k)%N][j] != s[(j+k)%N][i]) flag = false;
    }
    if(flag) ans += N;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int Adj[100][100] = { 0 };
int Stack[100] = { 0 }, d[100] = { 0 }, f[100] = { 0 };
int main(){
	int n, u, k, v;
	int i, j;
	int id, t = 0, stc, pid, id_check;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &u);
		scanf("%d", &k);
		for (j = 0; j < k; j++) {
			scanf("%d", &v);
			Adj[u - 1][j] = v;
		}
	}
	
	for (id_check = 0; id_check < n; id_check++) {
		if (d[id_check] != 0) {
			continue;
		} else {
			id = id_check;
			t++;
			d[id] = t;
			stc = 0;
			Stack[stc] = id;
			
			while (1) {
				pid = id;
				t++;
				for (i = 0; Adj[id][i] != 0; i++) {
					if (d[ Adj[id][i] - 1 ] == 0) {
						id = Adj[id][i] - 1;
						d[id] = t;
						stc++;
						Stack[stc] = id;
						break;
					}
				}
				if (pid == id) {
					Stack[stc] = 0;
					f[id] = t;
					stc--;
					if (stc < 0) break;
					id = Stack[stc];
				}
			}
		}
	}
	
	for (i = 0; i < n; i++) {
		printf("%d %d %d\n", i + 1, d[i], f[i]);
	}
	return 0;
}

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

vector<int> A[8];
int ans = 0;
int N;

void search(int a, int bit){
  if(a<0||a>=N) return;
  bit |= (1<<a);
  if (bit == (1<<N)-1) ans++;
  else {
    for (auto i: A[a]) {
      if(!(bit&(1<<i))) search(i, bit);
    }
    return;
  }
}
  
int main() {
  int M, a, b, bit=0; cin >> N >> M;
  for (int i=0; i<M; i++) {
    cin >> a >> b;
    A[a-1].push_back(b-1);
    A[b-1].push_back(a-1);
  }
  search(0, bit);
  cout << ans << "\n";
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

def factorization(n):
    cnt = 0
    while n%2==0:
        n /= 2
        cnt += 1
    return cnt

fac = [0] * N
for i in range(N):
    if a[i]%2==0:
        fac[i] = factorization(a[i])

print(sum(fac))

Measured memory_bytes: 4276
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<50
#define fst first
#define sec second
#define pb push_back
#define int long long
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(int itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(int itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef long long ll;
typedef pair<ll,ll> P;

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

  int n,m;
  cin >> n >> m;
  
  string s[n];
  REP(i,n) cin >> s[i];
  
  REP(i,n) cout << s[i] << endl << s[i] << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    List<String> list = new ArrayList<String>();
    for (int i = 0 ; i < k ; i++){
      list.add(Integer.toString(sc.nextInt()));
    }
    for (int i = n ; i < 100000 ; i++){
      String target = Integer.toString(i);
      if (judge(target, list)) {
        System.out.println(i);
        break;
      }
    }
    sc.close();
 }
 static boolean judge(String target ,List<String>l) {
   boolean b = true;
   for (String s : l){
     if (target.contains(s)) {
      b = false;
     }
    }
   return b;
 }
}

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

int a,b,c,n,ans=0;

signed main()
{
	cin>>a>>b>>c>>n;
	
	int pick1=min(a,n);
	ans+=pick1;
	n-=pick1;
	
	int pick2=min(b,n);
	n-=pick2;
	
	int pick3=min(c,n);
	ans-=pick3;
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3592
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;


int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<char> > c(h, vector<char>(w));
    vector<vector<char> > res(2*h, vector<char>(w));
    for(int row=0;row<h;row++){
        for(int col=0;col<w;col++){
            cin >> c[row][col];
        }
    }

    for(int row=0;row<2*h;row++){
        for(int col=0;col<w;col++){
            res[row][col] = c[row/2][col];
            cout << res[row][col];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

template <typename T>
using vec = vector<T>;

template <typename T>
using vec2 = vector<vector<T>>;

template <typename T>
using vec3 = vector<vector<vector<T>>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    const int inf = 1000000;
    int n;
    cin >> n;
    vec<int> a(n), cnt(inf + 10, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    sort(a.begin(), a.end());

    int ans = 0;

    vec<bool> isok(inf + 10, true);
    for (int i = 0; i < n; i++) {
        if (isok[a[i]] && cnt[a[i]] == 1) {
            ans++;
        }

        if (isok[a[i]]) {
            for (int j = 1;; j++) {
                int mult = j * a[i];
                if (mult <= inf) {
                    isok[mult] = false;
                } else {
                    break;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8196
#include <iostream>
#include <vector>
#include <string.h>
#include <vector>
#include <cmath>

using namespace std;
#define ll long long
#define endl "\n";

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    //freopen("r.txt", "r", stdin);
    int t;
    cin >> t;
    int c = 0;
    int pr = 0;
    while (t--) {
        int a, b;
        cin >> a >> b;
        if (a == b) {
            pr++;
            if (pr == 3) {
                cout << "Yes";
                return 0;
            }
        } else {
            pr = 0;
        }
    }
    // cout << (pr >= 3? "Yes":"No");
    cout << "No";
    return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
int main(void){
    int n,i;
    scanf("%d",&n);
    int a[n];
    for( i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=n-1;i>=0;i--){
        printf("%d",a[i]);
        if(i>0){
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 1828
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

int X[10][10];

int main() {
	int N, D;

	cin >> N >> D;

	int ans = ceil(N/(float)(2*D+1));

	cout << ans;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    string s = "PWGY";
    bool use[4]; memset(use, 0, sizeof(use));
    zep(i, 0, n){
        char c; cin >> c;
        zep(j, 0, 4){
            if(c == s[j]){
                use[j] = true;
            }
        } 
    }

    ll ans = 0;
    zep(j, 0, 4){
        if(use[j])ans++;
    }
    print((ans == 3)? "Three" : "Four")
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb(x) push_back(x)
#define TEST int inox,t;cin>>t; for(inox=1;inox<=t;inox++)
#define rep(i,n) for(i=0;i<n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
#define FAST    ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
#define modd 998244353 
 
int main(){

int a,b,c; cin>>a>>b>>c;
cout<<c<<" "<<a<<" "<<b;
}

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

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

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

        if x == y:
            return

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

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

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

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


N, M, K = map(int,input().split())
Friend_Net = UnionFind(N)
Block = [[] for i in range(N)]
friend = [0] * N

for i in range(M):
    A, B = map(int, input().split())
    friend[A-1] += 1
    friend[B-1] += 1
    Friend_Net.union(A-1, B-1)

for i in range(K):
    C, D = map(int, input().split())
    Block[C-1].append(D-1)
    Block[D-1].append(C-1)

for i in range(N):
    ans = Friend_Net.size(i) - friend[i]
    for b in Block[i]:
        if Friend_Net.same(i, b):
            ans -= 1
    print(ans-1)

Measured memory_bytes: 112544
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  int n,m; cin >> n >> m;
  vector<pair<int,int>> v(m);
  rep(i,m){
    int a,b; cin >> a >> b;
    a--;b--;
    v[i] = make_pair(b,a);
  }
  sort(v.begin(),v.end());
  
  int pos = -1;
  int cnt = 0;
  
  rep(i,m){
    if(v[i].second > pos){
      cnt++;
      pos = v[i].first-1;
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 1024
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    p = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    a_cnt = 0
    for i in range(n):
        if p[i] == i + 1:
            cnt += 1
        else:
            if cnt != 0:
                if cnt % 2 == 0:
                    a_cnt += cnt // 2
                else:
                    a_cnt += (cnt + 2 - 1) // 2
                cnt = 0
    if cnt != 0:
        if cnt % 2 == 0:
            a_cnt += cnt // 2
        else:
            a_cnt += (cnt + 2 - 1) // 2
    print(a_cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 52460
#include <stdio.h>
int main()
{
	int i;
	char n[4];
	while(scanf("%s", n)!=EOF)
	{
		i = 0;
		if(n[0] == n[2])
		{
			i = 1;
		}
		if(i == 1)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int , int > Pi;
const int INF = (1 << 30) - 1;
const ll LLINF = 1LL << 60;

int main()
{
    int N;
    int sum = 0;
    bitset < 2000005 > bt, temp;
    bt |= 1;
    cin >> N;
    for(int i = 0; i < N; i++) {
        int A;
        cin >> A;
        sum += A;
        temp = bt;
        temp <<= A;
        bt |= temp;
    }
    for(int i = (sum + 1) / 2; i < 2000005; i++) {
        if(bt[i]) {
            cout << i << endl;
            break;
        }
    }
    return (0);
}

Measured memory_bytes: 1024
N = int(input())
H = list(map(int, input().split())) # １行に別れてるとき

D = []
for i in range(N-1):
    D.append(H[i+1]-H[i])

ans = 0
up = True
down = False
for i in range(N-2):
    if i == 0 and D[i] < 0:
        ans += H[0]
        up = False
    if (D[i] > 0 and D[i+1] < 0) or (up and D[i+1] < 0):
        ans += H[i+1]
        up = False
    elif D[i] > 0 and D[i+1] == 0:
        up = True
    
    if (D[i] < 0 and D[i+1] > 0) or (down and D[i+1] > 0):
        ans -= H[i+1]
        down = False
    elif D[i] < 0 and D[i+1] == 0:
        down = True
if up or D[-1] > 0:
    ans += H[-1]


print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
 
int main(void) {
	int W, H, x, y, r;
	scanf("%d%d%d%d%d", &W, &H, &x, &y, &r);
	if (x>=r && x<=(W-r) && y>=r && y<=(H-r)) {
		printf("Yes\n");
	} 
	else {
		printf("No\n");
	}
	return 0;
}
 

Measured memory_bytes: 584
import sys
# sys.stdin = open('input.txt')
from collections import deque

def fillMatrix():
    for i in range(n):
        u, k, *v = map(int, input().split())
        for j in v:
            matrix[i][j-1] = 1

def bfs(s):
    status[s] = VISITING
    distance[s] = 0
    Q.append(s)
    while len(Q) > 0:
        u = Q.popleft()
        for v in range(n):
            if matrix[u][v] and status[v] == NOT_VISITED:
                status[v] = VISITING
                distance[v] = distance[u] + 1
                Q.append(v)
        status[u] = VISITED

n = int(input())
matrix = [[0]*n for i in range(n)]
INFTY = 1 << 21
distance = [INFTY] * n

NOT_VISITED = 0 # WHITE
VISITING = 1 # GRAY
VISITED = 2 # BLACK
status = [NOT_VISITED] * n
Q = deque()

fillMatrix()
bfs(0)

for i in range(n):
    ans = []
    ans.append(i+1)
    if distance[i] == INFTY:
        distance[i] = -1
    ans.append(distance[i])
    ans = map(str, ans)
    print(' '.join(ans))


Measured memory_bytes: 6080
import numpy as np
n, m, x = map(int, input().split())
Book = [list(map(int, input().split())) for _ in range(n)]
cost = [0 for _ in range(2**n)]
skill = [np.zeros(m) for _ in range(2**n)]
cost2 = []
for i in range(2**n):
    for j in range(n):
        if (i >> j) & 1:
            cost[i] += Book[j][0]
            skill[i] += np.array(Book[j])[1:m+1]
    if np.min(skill[i]) >= x:
        cost2.append(cost[i])
if len(cost2) > 0:
    print(min(cost2))
else:
    print(-1)

Measured memory_bytes: 27804
#pragma GCC optimize ("Ofast")
#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;
typedef long long int ll;
#define int long long int
#define pb push_back
#define fi first
#define se second
#define deb cerr << "Line no." << __LINE__
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;
#ifndef LOCAL
#define endl '\n'
#endif

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
	uniform_int_distribution<int> uid(l, r);
	return uid(rng);
}
int pwr(int a,int b){
	int ans = 1;
	while(b){
		if(b & 1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ans;
}
const int N = 1e5 + 5;
int dp[N], h[N];
void solve(){
	int n, k;
	cin >> n >> k;
	fr(i, 1, n){
		cin >> h[i];
	}
	dp[n] = 0;
	for(int i = n - 1; i >= 1; i--){
		dp[i] = 1e18;
		for(int j = i + 1; j <= min(i + k, n); j++){
			dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
		}
	}
	cout << dp[1];
}
signed main(){
  	IO;
  	#ifdef LOCAL
		freopen("inp.txt","r", stdin);
		// freopen("out.txt", "w", stdout);
	#endif
 	clock_t clk = clock();
  	int t = 1;
  	// cin >> t;
  	fr(tt, 1, t){
    	solve();
  	}
  	cerr << endl << (double)(clock() - clk) / CLOCKS_PER_SEC;
  	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cctype>
#include <vector>
#include <cassert>
using namespace std;
const int MAX_VARI = 11;
string S;
int cur = 0;
int vari = 0;
int formula();
int equation();
int factor();
int main(){
  while(cin >> S, S != "#"){
    //cur = 0;
    int flag = 0;
    for(int i = 0;i < 1<<11;i++){
      vari = i;
      cur = 0;
      if(equation() != 1){
	flag = 1;
	break;
      }
    }
    if(flag == 0)cout << "YES" << endl;
    else cout << "NO" << endl;
  
  }
  return 0;
}
int equation(){
  int a = formula();
  assert(S[cur] == '=');
  cur++;
  int b = formula();
  if(a == b)return 1;
  return 0;
}
int formula(){
  if(S[cur] == 'T'){
    cur++;
    return 1;
  }
  else if(S[cur] == 'F'){
    cur++;
    return 0;
  }
  else if(S[cur] >= 'a' && S[cur] <= 'k' ){
    cur++;
    if((vari & (1<<(S[cur-1] - 'a'))) == (1<<(S[cur-1] - 'a')))return 1;
    return 0;
  }
  else if(S[cur] == '-'){
    cur++;
    return formula()^1;
  }
  else if(S[cur] == '('){
    cur++;
    return factor();
  }
  return 0;
}
int factor(){
  int a,b;
  a = formula();
  char op = S[cur++];
  assert(op == '-' || op == '+' || op == '*');
  if(op == '-')cur++;
  b = formula();
  cur++;
  if(op == '*')return a&b;
  else if(op == '+')return a|b;
  return ((a == 0)? 1:((b == 1)? 1:0));
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int n,d;
    cin>>n>>d;
    int x[n][d];
    rep(i,n){
        rep(j,d){
            cin>>x[i][j];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int dis=0;
            for(int k=0;k<d;k++){
                dis+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            int m=floor(sqrt(dis));
            if(m*m==dis)    ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
//03
#include<iostream>

using namespace std;

int main(){
  for(int n,m;cin>>n>>m,n;){
    char pn[100][9];
    int pa[100];
    for(int i=0;i<n;i++){
      cin>>pn[i]>>pa[i];
    }
    int ans=0;
    while(m--){
      char b[9];
      cin>>b;
      for(int i=0;i<n;i++){
	bool f=false;
	for(int j=0;j<8;j++){
	  if(pn[i][j]!='*'){
	    f|=b[j]!=pn[i][j];
	  }
	}
	if(!f){
	  ans+=pa[i];
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    static final int MODULUS = 1_000_000_007;

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

        int N = sc.nextInt();

        System.out.println(solve(N));

        sc.close();
    }

    static int solve(int N) {
        return IntStream.rangeClosed(1, N).reduce((x, y) -> (int) ((long) x * y % MODULUS)).getAsInt();
    }
}

Measured memory_bytes: 25044
import java.util.Arrays;
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner scan = new Scanner(System.in);
		int a[]=new int[100+1];
		Arrays.fill(a, 0);

		while(scan.hasNext())
		{
			int in = scan.nextInt();
			a[in]++;
		}

		int max = 0;
		for(int i=1; i<a.length; i++)
		{
			if(max <=a[i])
				max=a[i];
		}
		for(int i=0; i<a.length; i++)
		{
			if(a[i]==max)
				System.out.println(i);
		}

	}

}

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

using namespace std;

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

#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

const int MAXN = 1e5 + 5;

char s[MAXN];
int n;
vector<pii> ans;

int main () {
    scanf("%s", s);
    n = strlen(s);

    if (s[n-1] == '1' || s[0] == '0') {
        puts("-1");
        return 0;
    }

    fto(i, 1, n-1) {
        if (s[i-1] == '1' && s[n-i-1] == '0') {
            puts("-1");
            return 0;
        }
    }

    int last = 1;
    fto(i, 2, n-1) {
        if (s[i-1] == '1') {
            fto(j, last, i-1)
                ans.pb(mp(j, i));
            last = i;
        }
    }
    ans.pb(mp(n-1, n));

    for(pii p: ans)
        printf("%d %d\n", p.ff, p.ss);

    return 0;
}



Measured memory_bytes: 2420
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            int ans = 1;

            for (int i = 0; i < N - 1; i++) {
                if (S[i + 1] != S[i]) {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13280
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	VI a(12); rep(i, 12)cin >> a[i]; sort(all(a));
	bool flag = true;
	rep(i, 3) {
		rep(j, 3) {
			if (a[j + i * 4] != a[j + i * 4 + 1])flag = false;
		}
	}
	puts(flag ? "yes" : "no");
}


Measured memory_bytes: 3132